Connecting Tech Pros Worldwide Help | Site Map

Why is this failing?

Billy Patton
Guest
 
Posts: n/a
#1: Jul 23 '05
If I comment out all down to the first fprintf , 6 lines. no problem
I uncommented one at a time until just the std::string* sp3 was commented out
and still everything went ok.
When I uncomment that line I get a seg fault.

Here's the core bt:
Core was generated by `Linux/32/test'.
Program terminated with signal 11, Segmentation fault.
#0 0x0811bb55 in _int_malloc ()
(gdb) bt
#0 0x0811bb55 in _int_malloc ()
#1 0x0811b58a in malloc ()
#2 0x080efd9e in operator new (sz=137509408)
at /apps/local-source/gcc/gcc-3.4.1/libstdc++-v3/libsupc++/new_op.cc:48
#3 0x080662e2 in t_String () at test.cxx:1971
#4 0x0804836d in main (argc=1, argv=0xbfff84f4) at test.cxx:87
(gdb) q


Notice #2 sz=137509408

/************************************************** ******************
************************* TEST OPERATOR != *************************
************************************************** *****************/
{
String s1("ABC");
String s2("abc");
String* sp1 = new String("abc");
String* sp2 = new String("ABC");
std::string s3("abc");
std::string* sp3 = new std::string("abc");
fprintf(stderr,"%d\n",__LINE__);
std::string* sp4 = new std::string("ABC");
fprintf(stderr,"%d\n",__LINE__);
OK(s1 != s1);
NOK(s1 != s2);
NOK(s1 != sp1);
OK(s1 != sp2);
NOK(s1 != s3);
NOK(s1 != sp3);
OK(s1 != sp4);
delete sp1;
delete sp2;
delete sp3;
delete sp3;
s2 = 1;
NOK(s1 != (short)1);
OK(s2 != (short)1);
NOK(s1 != (long)1);
OK(s2 != (long)1);
NOK(s1 != (int)1);
OK(s2 != (int)1);

}
LEAVE;
}

___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodology Group
Dallas, Texas, 214-480-4455, b-patton@ti.com
Victor Bazarov
Guest
 
Posts: n/a
#2: Jul 23 '05

re: Why is this failing?


Billy Patton wrote:
[color=blue]
> If I comment out all down to the first fprintf , 6 lines. no problem
> I uncommented one at a time until just the std::string* sp3 was
> commented out and still everything went ok.
> When I uncomment that line I get a seg fault.
>
> Here's the core bt:
> Core was generated by `Linux/32/test'.
> Program terminated with signal 11, Segmentation fault.
> #0 0x0811bb55 in _int_malloc ()
> (gdb) bt
> #0 0x0811bb55 in _int_malloc ()
> #1 0x0811b58a in malloc ()
> #2 0x080efd9e in operator new (sz=137509408)
> at /apps/local-source/gcc/gcc-3.4.1/libstdc++-v3/libsupc++/new_op.cc:48
> #3 0x080662e2 in t_String () at test.cxx:1971
> #4 0x0804836d in main (argc=1, argv=0xbfff84f4) at test.cxx:87
> (gdb) q
>
>
> Notice #2 sz=137509408
>
> /************************************************** ******************
> ************************* TEST OPERATOR != *************************
> ************************************************** *****************/
> {
> String s1("ABC");
> String s2("abc");
> String* sp1 = new String("abc");
> String* sp2 = new String("ABC");
> std::string s3("abc");
> std::string* sp3 = new std::string("abc");
> fprintf(stderr,"%d\n",__LINE__);
> std::string* sp4 = new std::string("ABC");
> fprintf(stderr,"%d\n",__LINE__);
> OK(s1 != s1);
> NOK(s1 != s2);
> NOK(s1 != sp1);
> OK(s1 != sp2);
> NOK(s1 != s3);
> NOK(s1 != sp3);
> OK(s1 != sp4);
> delete sp1;
> delete sp2;
> delete sp3;
> delete sp3;[/color]

Why are you deleting 'sp3' twice? Copy-paste error?
[color=blue]
> s2 = 1;
> NOK(s1 != (short)1);
> OK(s2 != (short)1);
> NOK(s1 != (long)1);
> OK(s2 != (long)1);
> NOK(s1 != (int)1);
> OK(s2 != (int)1);
>
> }
> LEAVE;
> }[/color]
REH
Guest
 
Posts: n/a
#3: Jul 23 '05

re: Why is this failing?



"Billy Patton" <bpatton@ti.com> wrote in message
news:Pine.LNX.4.61.0505251429310.9493@holster07.da l.design.ti.com...[color=blue]
> If I comment out all down to the first fprintf , 6 lines. no problem
> I uncommented one at a time until just the std::string* sp3 was commented[/color]
out[color=blue]
> and still everything went ok.
> When I uncomment that line I get a seg fault.
>
> Here's the core bt:
> Core was generated by `Linux/32/test'.
> Program terminated with signal 11, Segmentation fault.
> #0 0x0811bb55 in _int_malloc ()
> (gdb) bt
> #0 0x0811bb55 in _int_malloc ()
> #1 0x0811b58a in malloc ()
> #2 0x080efd9e in operator new (sz=137509408)
> at[/color]
/apps/local-source/gcc/gcc-3.4.1/libstdc++-v3/libsupc++/new_op.cc:48[color=blue]
> #3 0x080662e2 in t_String () at test.cxx:1971
> #4 0x0804836d in main (argc=1, argv=0xbfff84f4) at test.cxx:87
> (gdb) q
>
>
> Notice #2 sz=137509408
>
> /************************************************** ******************
> ************************* TEST OPERATOR != *************************
> ************************************************** *****************/
> {
> String s1("ABC");
> String s2("abc");
> String* sp1 = new String("abc");
> String* sp2 = new String("ABC");
> std::string s3("abc");
> std::string* sp3 = new std::string("abc");
> fprintf(stderr,"%d\n",__LINE__);
> std::string* sp4 = new std::string("ABC");
> fprintf(stderr,"%d\n",__LINE__);
> OK(s1 != s1);
> NOK(s1 != s2);
> NOK(s1 != sp1);
> OK(s1 != sp2);
> NOK(s1 != s3);
> NOK(s1 != sp3);
> OK(s1 != sp4);
> delete sp1;
> delete sp2;
> delete sp3;
> delete sp3;
> s2 = 1;
> NOK(s1 != (short)1);
> OK(s2 != (short)1);
> NOK(s1 != (long)1);
> OK(s2 != (long)1);
> NOK(s1 != (int)1);
> OK(s2 != (int)1);
>
> }
> LEAVE;
> }
>[/color]
You are deleting sp3 twice.

Your macros make reading your code confusing.

REH


Billy Patton
Guest
 
Posts: n/a
#4: Jul 23 '05

re: Why is this failing?


On Wed, 25 May 2005, REH wrote:
[color=blue]
>
> "Billy Patton" <bpatton@ti.com> wrote in message
> news:Pine.LNX.4.61.0505251429310.9493@holster07.da l.design.ti.com...[color=green]
>> If I comment out all down to the first fprintf , 6 lines. no problem
>> I uncommented one at a time until just the std::string* sp3 was commented[/color]
> out[color=green]
>> and still everything went ok.
>> When I uncomment that line I get a seg fault.
>>
>> Here's the core bt:
>> Core was generated by `Linux/32/test'.
>> Program terminated with signal 11, Segmentation fault.
>> #0 0x0811bb55 in _int_malloc ()
>> (gdb) bt
>> #0 0x0811bb55 in _int_malloc ()
>> #1 0x0811b58a in malloc ()
>> #2 0x080efd9e in operator new (sz=137509408)
>> at[/color]
> /apps/local-source/gcc/gcc-3.4.1/libstdc++-v3/libsupc++/new_op.cc:48[color=green]
>> #3 0x080662e2 in t_String () at test.cxx:1971
>> #4 0x0804836d in main (argc=1, argv=0xbfff84f4) at test.cxx:87
>> (gdb) q
>>
>>
>> Notice #2 sz=137509408
>>
>> /************************************************** ******************
>> ************************* TEST OPERATOR != *************************
>> ************************************************** *****************/
>> {
>> String s1("ABC");
>> String s2("abc");
>> String* sp1 = new String("abc");
>> String* sp2 = new String("ABC");
>> std::string s3("abc");
>> std::string* sp3 = new std::string("abc");
>> fprintf(stderr,"%d\n",__LINE__);
>> std::string* sp4 = new std::string("ABC");
>> fprintf(stderr,"%d\n",__LINE__);
>> OK(s1 != s1);
>> NOK(s1 != s2);
>> NOK(s1 != sp1);
>> OK(s1 != sp2);
>> NOK(s1 != s3);
>> NOK(s1 != sp3);
>> OK(s1 != sp4);
>> delete sp1;
>> delete sp2;
>> delete sp3;
>> delete sp3;
>> s2 = 1;
>> NOK(s1 != (short)1);
>> OK(s2 != (short)1);
>> NOK(s1 != (long)1);
>> OK(s2 != (long)1);
>> NOK(s1 != (int)1);
>> OK(s2 != (int)1);
>>
>> }
>> LEAVE;
>> }
>>[/color]
> You are deleting sp3 twice.
>
> Your macros make reading your code confusing.
>
> REH[/color]

It makes no difference about deleting sp3 twice. It doesn't get that far.
It will not even get to the second fprintf.

___ _ ____ ___ __ __
/ _ )(_) / /_ __ / _ \___ _/ /_/ /____ ___
/ _ / / / / // / / ___/ _ `/ __/ __/ _ \/ _ \
/____/_/_/_/\_, / /_/ \_,_/\__/\__/\___/_//_/
/___/
Texas Instruments ASIC Circuit Design Methodology Group
Dallas, Texas, 214-480-4455, b-patton@ti.com
Lionel B
Guest
 
Posts: n/a
#5: Jul 23 '05

re: Why is this failing?


"Billy Patton" <bpatton@ti.com> wrote in message news:Pine.LNX.4.61.0505251429310.9493@holster07.da l.design.ti.com...[color=blue]
> If I comment out all down to the first fprintf , 6 lines. no problem
> I uncommented one at a time until just the std::string* sp3 was commented out
> and still everything went ok.
> When I uncomment that line I get a seg fault.
>[/color]

[...]
[color=blue]
> String s1("ABC");[/color]

What is "String" ? Perhaps the problem is there (just guessing, as we can't see the code for it).

--
Lionel B

Thomas Matthews
Guest
 
Posts: n/a
#6: Jul 23 '05

re: Why is this failing?


Billy Patton wrote:[color=blue]
> If I comment out all down to the first fprintf , 6 lines. no problem
> I uncommented one at a time until just the std::string* sp3 was
> commented out and still everything went ok.
> When I uncomment that line I get a seg fault.
>
> Here's the core bt:
> Core was generated by `Linux/32/test'.
> Program terminated with signal 11, Segmentation fault.
> #0 0x0811bb55 in _int_malloc ()
> (gdb) bt
> #0 0x0811bb55 in _int_malloc ()
> #1 0x0811b58a in malloc ()
> #2 0x080efd9e in operator new (sz=137509408)
> at /apps/local-source/gcc/gcc-3.4.1/libstdc++-v3/libsupc++/new_op.cc:48
> #3 0x080662e2 in t_String () at test.cxx:1971
> #4 0x0804836d in main (argc=1, argv=0xbfff84f4) at test.cxx:87
> (gdb) q
>
>
> Notice #2 sz=137509408
>
> /************************************************** ******************
> ************************* TEST OPERATOR != *************************
> ************************************************** *****************/
> {
> String s1("ABC");
> String s2("abc");
> String* sp1 = new String("abc");
> String* sp2 = new String("ABC");
> std::string s3("abc");[/color]
Try this:
std::string * sp3 = new std::string;
*sp3 = "abc";
std::string * sp4 = new std::string;
*sp4 = "ABC";
[color=blue]
> std::string* sp3 = new std::string("abc");
> fprintf(stderr,"%d\n",__LINE__);
> std::string* sp4 = new std::string("ABC");
> fprintf(stderr,"%d\n",__LINE__);
> OK(s1 != s1);[/color]

By the way, does your String class define the
!= operator for std::string?

Why do you have sp1 as a pointer to a dynamically
allocated string (and same for the others)?
Did you want the following:
String * sp1 = &s1;

Generally, what you are doing is testing the
dynamically allocated memory (via new) versus
the local memory.

When testing equivalence operators, the location
of the objects is irrevalent. You are testing
the comparison of the value of one String versus
another. I don't see the point of using the
dynamic memory allocation.

--
Thomas Matthews

C++ newsgroup welcome message:
http://www.slack.net/~shiva/welcome.txt
C++ Faq: http://www.parashift.com/c++-faq-lite
C Faq: http://www.eskimo.com/~scs/c-faq/top.html
alt.comp.lang.learn.c-c++ faq:
http://www.comeaucomputing.com/learn/faq/
Other sites:
http://www.josuttis.com -- C++ STL Library book
http://www.sgi.com/tech/stl -- Standard Template Library
Closed Thread