...
Subclause 7.23.7.2 of the C Standard paragraph 3 [ISO/IEC 9899:2024] says,
The fgets function returns s if successful. If end-of-file is encountered and no characters have been read into the array, the contents of the array remain unchanged and a null pointer is returned. If a read error occurs during the operation, the members of the array have unspecified values and a null pointer is returned.
...
Rule | Severity | Likelihood | Remediation Cost | Priority | Level |
|---|---|---|---|---|---|
FIO37-C | High | Probable | Medium | P12 | L1 |
Automated Detection
Tool | Version | Checker | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
| Astrée |
| Supported: Astrée reports defects due to returned (empty) strings. | |||||||
| Axivion Bauhaus Suite |
| CertC-FIO37 | |||||||
| CodeSonar |
| (general) | Considers the possibility that fgets() and fgetws() may return empty strings (Warnings of various classes may be triggered depending on subsequent operations on those strings. For example, the noncompliant code example cited above would trigger a buffer underrun warning.) | ||||||
| Compass/ROSE | Could detect some violations of this rule (In particular, it could detect the noncompliant code example by searching for | ||||||||
| Helix QAC |
| DF4911, DF4912, DF4913 | |||||||
| LDRA tool suite |
| 44 S | Enhanced enforcement | ||||||
| Parasoft C/C++test |
| CERT_C-FIO37-a | Avoid accessing arrays out of bounds | ||||||
| Polyspace Bug Finder |
| CERT C: Rule FIO37-C | Checks for use of indeterminate string (rule fully covered) |
...