JavaScript is not currently enabled, but is required for full CodeSonar manual search and browse functionality.

If you are viewing this file in your hub's Web GUI, enable JavaScript in your browser: you will also need it for GUI functionality.

If you opened this file directly from disk, your browser may be directly suppressing JavaScript functionality: certain browsers perform this suppression on local files (but not files delivered by web servers) for security reasons.

CodeSonar® 9.2p0 CONFIDENTIAL CodeSecure Inc
C and C++


LANG.ERRCODE.NOTEST : Missing Test of Error Code

Summary

The code calls a function that sets errno to non-zero on failure, but does not subsequently check whether errno is equal to zero.

The functions that are subject to this checking are specified using the ERRNO_SETTING_FUNCTIONS configuration parameter.

Properties

Class Name Missing Test of Error Code
Significance style
Mnemonic LANG.ERRCODE.NOTEST
Categories
MisraC2025 MisraC2025:22.9 The value of errno shall be tested against zero after calling an errno-setting-function
  MisraC2025:D.4.7 If a function returns error information, then that error information shall be tested
MisraC2023 MisraC2023:22.9 The value of errno shall be tested against zero after calling an errno-setting-function
  MisraC2023:D.4.7 If a function returns error information, then that error information shall be tested
Misra2012 Misra2012:22.9 The value of errno shall be tested against zero after calling an errno-setting-function
  Misra2012:D.4.7 If a function returns error information, then that error information shall be tested
Misra2004 Misra2004:16.10 If a function returns error information, then that error information shall be tested
AUTOSARC++14 AUTOSARC++14:M0-3-2 If a function generates error information, then that error information shall be tested.
MisraC++2008 MisraC++2008:0-3-2 If a function generates error information, then that error information shall be tested.
TS17961 TS17961:5.24-inverrno Incorrectly setting and using errno
CERT-C CERT-C:ERR33-C Detect and handle standard library errors
  CERT-C:POS54-C Detect and handle POSIX library errors
Availability Available for C and C++.
Enabling Checks for this warning class are disabled by default. To enable them, add the following WARNING_FILTER rule to the project configuration file.
WARNING_FILTER += allow class="Missing Test of Error Code"

Example

#include <errno.h>
#include <stdio.h>

int compare_to_zero(FILE *fp){

  (void) ftell(fp);                /* 'Missing Test of Error Code' warning issued here
                                    * - errno is not checked between return from this call and the next call to ftell()
                                    */

  (void) ftell(fp);                                   /* ok: immediately followed by check errno!=0 */
  if (errno != 0){ return 1; }

  (void) ftell(fp);                                   /* ok: immediately followed by check errno==0 */
  if (errno == 0) {  }
  else {return 1;}

  (void) ftell(fp);                /* 'Missing Test of Error Code' warning issued here
                                    * - following check errno>0 is not a test for equality with zero
                                    */
  if (errno > 0){ return 1; }

  return 0;
}

int compare_to_nonzero(FILE *fp){
  (void) ftell(fp);                /* 'Missing Test of Error Code' warning issued here
                                    * - following check errno==15 is not a test for equality with zero
                                    */
  if (errno == 15){ return 1; }
  return 0;
}

int not_all_paths(FILE *fp, int i){
  (void) ftell(fp);                /* 'Missing Test of Error Code' warning issued here
                                    * - errno is not checked when i!=100
                                    */
  if (i == 100){
    if (errno!=0) {return 1;}
  }
  return 0;
}

Relevant Configuration File Parameters

The following configuration file parameters affect checks for this warning class.

 

To report problems with this documentation, please visit https://support.codesecure.com/.