Article View: gnu.gcc.help
Article #51054Looking for help with GNU CC compiler...
From: 24-Jun-1993 2317 +0000
Date: Fri, 25 Jun 1993 03:23
Date: Fri, 25 Jun 1993 03:23
85 lines
2503 bytes
2503 bytes
The following code fragment performs the following:
1. Initially allocates a record buffer of 1024 characters.
2. Reads a record.
3. Scans the buffer for a particular set of characters.
4. If characters are not found then
4.1. Reallocates the record buffer by adding another 1024 characters
while leaving the character pointer in position.
4.2. Reads another record effectively concatenating it to the first record.
4.3. Go to 3.
5. If one of the desired characters is found then
5.1. Exit the loop
5.2. Deallocates the record buffer
5.3. Continues with the rest of the program.
.
.
.
.
record_size = 1024;
memsize = record_size;
minbufptr = malloc (memsize);
*minbufptr = END_REC;
sbufptr = minbufptr;
while (*sbufptr != END_FORM)
{
sys_status = get_a_record (sbufptr,
record_size,
scanner_type,
error_count);
if (sys_status != SUCCESS)
{
return (sys_status);
}
while ((*sbufptr != END_REC) &&
(*sbufptr != END_FORM) &&
(*sbufptr != 0))
{
sbufptr++;
}
if (*sbufptr == END_REC)
{
ptroffset = sbufptr - minbufptr;
if ((record_size/2) <= ptroffset)
{
memsize += record_size;
realloc (minbufptr, memsize);
sbufptr = minbufptr + ptroffset;
}
}
}
free (minbufptr);
.
.
.
.
The problem I am having is that on the second pass the FREE statement
causes a signal 11 segmentation error. The size of memsize at the time is
4096, therefore the FREE statement is trying to deallocate a 4096 character
buffer. What would cause a segmentation error?
I would appreciate any suggestions you could give.
Thanks in advance,
Paul Anastas
Technical Details
Message-ID:
<9306250318.AA28448@easynet.crl.dec.com>Path:
arc1-ca.pugleaf.net!gmd.de!rrz.uni-koeln.de!news.dfn.de!darwin.sura.net!math.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!usdev.enet.DEc.COM!panastasShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 11318c,bb4e1c890053b6d8,start X-Google-Attributes: gid11318c,public X-Google-ArrivalTime: 1993-06-25 00:59:11 PST Path: arc1-ca.pugleaf.net!gmd.de!rrz.uni-koeln.de!news.dfn.de!darwin.sura.net!math.ohio-state.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!usdev.enet.DEc.COM!panastas From: panastas@usdev.enet.DEc.COM (24-Jun-1993 2317 +0000) Newsgroups: gnu.gcc.help Subject: Looking for help with GNU CC compiler... Date: 24 Jun 1993 23:23:03 -0400 Organization: GNUs Not Usenet Lines: 85 Sender: daemon@cis.ohio-state.edu Distribution: gnu Message-ID: <9306250318.AA28448@easynet.crl.dec.com>