Miscellaneous-NoDiscardedReturnCode

Do not ignore return values of functions

Required inputs: IR

Most C functions return error codes. Ignoring the return value of those functions will silently ignore errors. This can cause incorrect behavior as the program continues despite an error.

This rule checks that integer return values are used and not ignored. To discard a return value, cast the result of the function call to void.

Example
// Propagate error:
if (fseek(f, 0, SEEK_SET) != 0)
{
    return ERR_CANNOT_SEEK;
}

// Ignore errors when closing the file:
(void)fclose(f);

Possible Messages

Key

Text

Severity

Disabled

discarded_return

Return value of function discarded.

None

False

Options

error_types

error_types : set[bauhaus.analysis.config.ShortTypeName] = set()

User defined error type names (if empty, all ignored int values are reported).
 

inspect_template_instances

inspect_template_instances : bool = False

Whether calls in template instances should be reported.
 

whitelist

whitelist

Type: dict[bauhaus.analysis.config.FileGlobPattern, list[bauhaus.analysis.config.GlobPattern]]

Default:

{
   'setjmp.h': ['setjmp', 'longjmp'],
   'signal.h': ['signal', 'raise'],
   'stdio.h': ['printf'],
   'string.h': ['str[!n]*'],
   'time.*': ['*']
}
Dictionary of header globbing to (list of) function names whose return codes can be ignored.