Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

fucking buffer boundaries

Name: Anonymous 2010-12-28 7:18

./shit.c:284: Medium: fgetc
Check buffer boundaries if calling this function in a loop
and make sure you are not in danger of writing past the allocated space.

./shit.c:284:9:  [1] (buffer) fgetc:
Check buffer boundaries if used in a loop.


/* there's a reason for using this sizing, don't hate */
unsigned int textfilesize(FILE *stream)
{
 auto unsigned int counter;
 counter = 0;
 while (fgetc(stream) != EOF)
  counter++;
 rewind(stream);  /* fseek(stream, 0L, SEEK_SET); */
 return counter;
}

Name: Anonymous 2010-12-28 8:16

>>1
We've discussed this loads of times before[1], you're supposed to use fstat.

unsigned int textfilesize(FILE *f)
{
  struct stat st;
  if(fstat(fileno(f), &st))
    return 0;
  return st.st_size;
}


[1] Get /prog/scrape

Name: Anonymous 2010-12-28 8:33

>>2
Even he didn't want to use fstat, he could have just used fseek with SEEK_END argument, and then a ftell call to see the size.
Reading the entire file just to get the size is inefficient.

Name: Anonymous 2010-12-28 8:45

OP wants to get the size of the character stream inside the file.

Name: Anonymous 2010-12-29 5:31

>>3
Except that SEEK_END gives undefined behaviour in C99 because of some bullshit about trailing null characters.

Name: Anonymous 2011-02-04 11:59


Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List