
...
Understanding the difference between text mode and binary mode with file streams is critical when working with functions that operate on them. Setting the file position indicator to end-of-file with fseek()
has undefined behavior for a binary stream. In addition, the return value of ftell()
for streams opened in text mode is useful only in calls to fseek()
, not for determining file sizes or for any other use. As such, fstat()
or other platform-equivalent functions should be used to determine the size of a file.
Recommendation | Severity | Likelihood |
---|
Detectable | Repairable | Priority | Level |
---|---|---|---|
FIO19-C | Low | Unlikely |
Yes | Yes |
P3 | L3 |
Automated Detection
Tool | Version | Checker | Description | ||||||
---|---|---|---|---|---|---|---|---|---|
LDRA tool suite |
| 44 S | Enhanced Enforcement |
Bibliography
[IEEE Std 1003.1:2013] | XSH, System Interfaces, fopen XSH, System Interfaces, fwrite |
[ISO/IEC 9899:2011] | Section 7.21.3, "Files" Section 7.21.9.2, "The fseek Function"Section 7.21.9.4, "The ftell Function" |
[MSDN] | "ftell" |
...
...