C and C++


LANG.ERRCODE.NOTEST : Missing Test of Error Code

要旨

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.

プロパティ

クラス名 Missing Test of Error Code
日本語クラス名 Missing Test of Error Code
クラス分類 スタイル (style)
ニーモニック LANG.ERRCODE.NOTEST
カテゴリー
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 5.24. 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
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっています。チェックを有効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += allow class="Missing Test of Error Code"

#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;
}

関連のある設定ファイルパラメータ

設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。