File read failure

Discussion in 'C Programming' started by manu, Jan 6, 2010.

  1. manu

    manu Guest

    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?
     
    manu, Jan 6, 2010
    #1
    1. Advertising

  2. On 6 Jan, 06:50, manu <> wrote:

    > 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?
     
    Nick Keighley, Jan 6, 2010
    #2
    1. Advertising

  3. manu <> writes:

    > 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>
    --
    Ben.
     
    Ben Bacarisse, Jan 6, 2010
    #3
  4. On Tue, 5 Jan 2010 22:50:11 -0800 (PST), manu <>
    wrote:

    > 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.
     
    David Thompson, Jan 14, 2010
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. akhare1
    Replies:
    4
    Views:
    850
    Alvin Bruney [MVP]
    Aug 1, 2004
  2. Ilias Lazaridis
    Replies:
    0
    Views:
    583
    Ilias Lazaridis
    Feb 1, 2005
  3. Replies:
    0
    Views:
    482
  4. Sreejith K
    Replies:
    24
    Views:
    1,032
    Sreejith K
    Mar 24, 2009
  5. Alex Dowad
    Replies:
    4
    Views:
    273
    Michel Demazure
    May 1, 2010
Loading...

Share This Page