mirror of
https://github.com/byteworksinc/ORCALib.git
synced 2025-02-06 13:30:40 +00:00
Avoid errors caused by fseek after ungetc on read-only files.
The error could occur because fseek calls fflush followed by ftell. fflush would reset the file position as if the characters in the putback buffer were removed, but ftell would still see them and try to adjust for them (in the case of a read-only file). This could result in trying to seek before the beginning of the file, producing an error. Here is a program that was affected: #include <stdio.h> int main(void) { FILE *f = fopen("somefile","r"); if (!f) return 0; fgetc(f); ungetc('X', f); fseek(f, 0, SEEK_CUR); if (ferror(f)) puts("error encountered"); }
This commit is contained in:
parent
219e4352a0
commit
463d24a028
Loading…
x
Reference in New Issue
Block a user