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

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