File read failure

M

manu

Hi all,

Im trying to populate structure from csv files. Each csv file is of
3MB and there are 24 files in total.A function will populate the
structure from these files. The same function when called twice, the
second cycle fails on a particular file that to on a fixed line.
While debugging we could find that the function which reads a line
from the file is not reading the entire line. The function uses fgetc
() for getting the characters from the line and this fuction returns
-1 before the End of line.

Please give your valuable inputs on this issue.


This is the call stack

NTDLL! 7c9100e8()
_heap_alloc_base(unsigned int 4144) line 161
_heap_alloc_dbg(unsigned int 4096, int 2, const char * 0x0047075c
`string', int 59) line 367 + 9 bytes
_nh_malloc_dbg(unsigned int 4096, int 1768161280, int 2, const char *
0x0047075c `string', int 59) line 242 + 21 bytes
_malloc_dbg(unsigned int 4096, int 2, const char * 0x0047075c
`string', int 59) line 163 + 27 bytes
_getbuf(_iobuf * 0x00477750) line 59 + 19 bytes
_flsbuf(int 69, _iobuf * 0x00477750) line 153 + 9 bytes
write_char(int 69, _iobuf * 0x00477750, int * 0x00136da0) line 1083 +
75 bytes
_output(_iobuf * 0x00477750, const char * 0x00465461, char *
0x00137004) line 393 + 21 bytes
printf(const char * 0x00465460 `string') line 60 + 18 bytes
FhReadLineFromFile(_iobuf * 0x004777f0, unsigned char * 0x001370e8)
line 306 + 15 bytes

Is it anything related to heap allocation?
 
N

Nick Keighley

Im trying to populate structure from csv files. Each csv file is of
3MB and there are 24 files in total.A function will populate the
structure from these files.

you're reading a bunch of files into a structure
The same function when called twice, the
second cycle fails

a function fails on its second call

on a particular file that to on a fixed line.

it always fails on the same line in the same file. Is tehre anything
odd about the line?

While debugging we could find that the function which reads a line
from the file is not reading  the entire line. The function uses fgetc
() for getting the characters from the line and this fuction returns
-1 before the End of line.

might be an error. What does errno say (I spent 10s checking the
definition of fgetc(), did you?).
Please give your valuable inputs on this issue.

This is the call stack

NTDLL! 7c9100e8()
_heap_alloc_base(unsigned int 4144) line 161
_heap_alloc_dbg(unsigned int 4096, int 2, const char * 0x0047075c
`string', int 59) line 367 + 9 bytes
_nh_malloc_dbg(unsigned int 4096, int 1768161280, int 2, const char *
0x0047075c `string', int 59) line 242 + 21 bytes
_malloc_dbg(unsigned int 4096, int 2, const char * 0x0047075c
`string', int 59) line 163 + 27 bytes
_getbuf(_iobuf * 0x00477750) line 59 + 19 bytes
_flsbuf(int 69, _iobuf * 0x00477750) line 153 + 9 bytes
write_char(int 69, _iobuf * 0x00477750, int * 0x00136da0) line 1083 +
75 bytes
_output(_iobuf * 0x00477750, const char * 0x00465461, char *
0x00137004) line 393 + 21 bytes
printf(const char * 0x00465460 `string') line 60 + 18 bytes
FhReadLineFromFile(_iobuf * 0x004777f0, unsigned char * 0x001370e8)
line 306 + 15 bytes

Is it anything related to heap allocation?

have you tried a debugger?
 
B

Ben Bacarisse

manu said:
Im trying to populate structure from csv files. Each csv file is of
3MB and there are 24 files in total.A function will populate the
structure from these files. The same function when called twice, the
second cycle fails on a particular file that to on a fixed line.
While debugging we could find that the function which reads a line
from the file is not reading the entire line. The function uses fgetc
() for getting the characters from the line and this fuction returns
-1 before the End of line.

Please give your valuable inputs on this issue.

Almost impossible without code. If there is a lot of code, you could
post an extract, but it is better to try to remove code until you get
a minimal program that still has the problem. Often, just doing that
reveals the problem.

<snip>
 
D

David Thompson

Hi all,

Im trying to populate structure from csv files. Each csv file is of
3MB and there are 24 files in total.A function will populate the
structure from these files. The same function when called twice, the
second cycle fails on a particular file that to on a fixed line.
While debugging we could find that the function which reads a line
from the file is not reading the entire line. The function uses fgetc
() for getting the characters from the line and this fuction returns
-1 before the End of line.
Is the symptom affected by changing the data, especially the lines
before the failure line e.g. shorten, lengthen, add fields, delete
fields, add escapes, delete escapes? Or by doing the files in a
different order, or doing different files?
Please give your valuable inputs on this issue.


This is the call stack
Captured how/when? It certainly isn't calling fgetc at this point.
NTDLL! 7c9100e8()
_heap_alloc_base(unsigned int 4144) line 161
_heap_alloc_dbg(unsigned int 4096, int 2, const char * 0x0047075c
`string', int 59) line 367 + 9 bytes
_nh_malloc_dbg(unsigned int 4096, int 1768161280, int 2, const char *
0x0047075c `string', int 59) line 242 + 21 bytes
_malloc_dbg(unsigned int 4096, int 2, const char * 0x0047075c
`string', int 59) line 163 + 27 bytes
_getbuf(_iobuf * 0x00477750) line 59 + 19 bytes
_flsbuf(int 69, _iobuf * 0x00477750) line 153 + 9 bytes
write_char(int 69, _iobuf * 0x00477750, int * 0x00136da0) line 1083 +
75 bytes
_output(_iobuf * 0x00477750, const char * 0x00465461, char *
0x00137004) line 393 + 21 bytes
printf(const char * 0x00465460 `string') line 60 + 18 bytes
FhReadLineFromFile(_iobuf * 0x004777f0, unsigned char * 0x001370e8)
line 306 + 15 bytes
This stack says your 'FhReadLine...' function line 306 is calling
printf; is that correct? It's not consistent with your description of
the function above.

Are all those 'string's really the actual string 'string', or have you
or your tool masked some data? The top three appear intended to be a
sourcefilename (with linenumber), and it would be very unusual,
although not impossible, to have a sourcefile named 'string'.
Is it anything related to heap allocation?

If it is faulting at the point shown, probably. It appears to be
making a reasonable attempt to allocate a buffer to do some output.
A fault here is probably because the 'arena' aka heap is damaged, most
likely by buffer overrun or stale pointer sometime earlier. If you can
run under a heap-debugger like valgrind, that might pinpoint the
problem. Alternatively try the usual but tedious approach of removing
chunks of functionality to narrow it down, being sure to check the
output carefully because memory clobbers can cause widely varied and
apparently unrelated problems; if a particular symptom disappears it
doesn't necessarily mean the problem is fixed, it might merely have
moved somewhere else where it causes a less noticeable symptom, or in
the worse case no detectable symptom at all.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top