The C standard Standard [ISO/IEC 9899:2011] defines the fwrite() function as follows [ISO/IEC 9899:2011]:
Synopsis
size_t fwrite(const void *restrict ptr, size_t size, size_t nmemb, FILE *restrict stream);Description
The
fwrite()function writes, from the array pointed to byptr, up tonmembelements whose size is specified bysize, to the stream pointed to bystream. For each object,sizecalls are made to thefputc()function, taking the values (in order) from an array ofunsigned charexactly overlaying the object. The file position indicator for the stream (if defined) is advanced by the number of bytes successfully written. If an error occurs, the resulting value of the file position indicator for the stream is indeterminate.
...
In this noncompliant code example, the size of the buffer is stored in size1, but size2 number of characters are written in to the file. If size2 is greater than size1, write() will not stop copying characters at the null character.
...
Recommendation | Severity | Likelihood | Remediation Cost | Priority | Level |
|---|---|---|---|---|---|
FIO18-C | Medium | Probable | Medium | P8 | L2 |
Related Guidelines
...
Bibliography
...
| ] | Section 7.21.8.2, "The fwrite |
...
| Function" |
Bibliography
...
...