If either of the C Standard
fgetws() functions fail, the contents of the array being written is indeterminate. (See undefined behavior 170.) It is necessary to reset the string to a known value to avoid errors on subsequent string manipulation functions.
Noncompliant Code Example
In this noncompliant code example, an error flag is set if
fgets() fails. However,
buf is not reset and has indeterminate contents:
In this compliant solution,
buf is set to an empty string if
fgets() fails. The equivalent solution for
fgetws() would set
buf to an empty wide string.
FIO40-C-EX1: If the string goes out of scope immediately following the call to
fgetws() or is not referenced in the case of a failure, it need not be reset.
|LDRA tool suite|
|44 S||Enhanced enforcement|
Reset strings on fgets() or fgetws() failure
|CERT C: Rule FIO40-C||Checks for use of indeterminate string (rule fully covered)|