Chi Li - 2023-03-03

Cppcheck can identify unchecked return values by using a user-defined configuration file with the following configuration.

<def>
<function name="XX">
<use-retval>
</use-retval></function>
</def>

However, I have not found a configuration that supports detection of incorrect return value checks.

For instance, can Cppcheck identify the incorrect return value check of the fgets function in the following code:

if (fgets(data, 100, stdin) < 0){
            printLine("fgets failed!");
            exit(1);
 }

Here is the correct way to check the return value of the fgets function:

if (fgets(data, 100, stdin) == NULL){
            printLine("fgets failed!");
            exit(1);
 }