Mail Archives: djgpp/2000/02/29/14:46:40
From: | Erik Berglund <erik2 DOT berglund AT telia DOT com>
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Re: ANY help would be greatly appreciated...
|
Lines: | 73
|
Message-ID: | <yNTu4.988$y3.193543168@newsb.telia.net>
|
Date: | Tue, 29 Feb 2000 17:58:54 GMT
|
NNTP-Posting-Host: | 194.237.158.107
|
X-Complaints-To: | abuse AT telia DOT com
|
X-Trace: | newsb.telia.net 951847134 194.237.158.107 (Tue, 29 Feb 2000 18:58:54 CET)
|
NNTP-Posting-Date: | Tue, 29 Feb 2000 18:58:54 CET
|
Organization: | Telia Internet
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Reply-To: | djgpp AT delorie DOT com
|
Tim <opus AT wam DOT umd DOT edu> wrote:
>
> Exiting due to signal SIGSEGV
> General Protection Fault at eip=00011d23
> eax=2074752f ebx=0003032c ecx=0003036c edx=00030364 esi=00000038
> edi=00000038
> ebp=01b86f10 esp=01b86f00 program=C:\BSO\ACCESS~1\CONVERT.EXE
> cs: sel=00a7 base=83405000 limit=01b86fff
> ds: sel=00af base=83405000 limit=01b86fff
> es: sel=00af base=83405000 limit=01b86fff
> fs: sel=0087 base=00008250 limit=0000ffff
> gs: sel=00bf base=00000000 limit=0010ffff
> ss: sel=00af base=83405000 limit=01b86fff
> App stack: [01b87000..01b07000] Exceptn stack: [00029520..000275e0]
>
> Call frame traceback EIPs:
> 0x00011d23
> 0x0001026c
> 0x0000e593
> 0x00001e47
> 0x000025fa
> 0x00011796
>
> My code is here, the offending line it seems (or at least where the
> program dumps out with a seg fault is the line in the function
> stripBlanks() that I've isolated in <<<<<| xxxxx |>>>>>. I've
> iincluded the other code in case someone might actually bother to see
> if there is something else wrong. However, as I said before, my driver
> works perfectly in UNIX, but crashes in DOS/Windows. The driver is at
> the very bottom, along with the correct output followed by the
> incorrect output. Thanks in advance to anyone who cares to take the
> time to help me.
>
> string& string::operator +(string& x) {
> if(x.length!=0) {
> int newlength = length + x.length;
> char *tempstring = new char[newlength+1]; <--- 1.newlength
> int counter, counter2;
>
> for(counter=0; counter < length; counter++) {
> tempstring[counter] = data[counter];
> }
> tempstring[counter] = '\0';
> cout << "This is from inside +: " << tempstring << endl;
> for(counter2=0; counter2 < x.length; counter2++) {
> tempstring[counter + counter2] = x.data[counter2];
> }
> tempstring[counter + counter2] = '\0'; <--- 2.before cout
> cout << "This is from inside +: " << tempstring << endl;
> delete [] data;
> length = newlength;
> data = tempstring;
> }
> return *this;
> }
I think I've found the error. It was in string operator,
see included text "<---". The problem before was that
the new allocation at <---1. was too small and the routine
was writing past the end of the allocated buffer, and
that caused a SIGSEGV later in another new (which is
correct in itself).
<---2. is needed because otherwise the cout output will
be incorrect.
Hope this helps,
--
Erik Berglund
erik2 DOT berglund AT telia DOT com
- Raw text -