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.ITEST : Inappropriate Test of Error Code

要旨

The value of errno is tested, but the last function call was not to a function that can set errno.

For this warning class, CodeSonar will treat a function as setting errno if it is specified using the ERRNO_SETTING_FUNCTIONS configuration parameter.

プロパティ

クラス名 Inappropriate Test of Error Code
日本語クラス名 Inappropriate Test of Error Code
クラス分類 スタイル (style)
ニーモニック LANG.ERRCODE.ITEST
カテゴリー
MisraC2025 MisraC2025:22.10 The value of errno shall only be tested when the last function to be called was an errno-setting-function
MisraC2023 MisraC2023:22.10 The value of errno shall only be tested when the last function to be called was an errno-setting-function
Misra2012 Misra2012:22.10 The value of errno shall only be tested when the last function to be called was an errno-setting-function
Misra2004 Misra2004:20.5 The error indicator errno shall not be used
AUTOSARC++14 AUTOSARC++14:M19-3-1 The error indicator errno shall not be used.
MisraC++2008 MisraC++2008:19-3-1 The error indicator errno shall not be used.
JSF++ JSF++:17 The error indicator errno shall not be used.
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっています。チェックを有効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += allow class="Inappropriate Test of Error Code"

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

void noerrno(void){
  /* errno is never set by noerrno() or any of its callees */
}

int test_ftell_errno(FILE *fp){
    (void) ftell(fp);
    if (errno !=0) {                                 /* ok: last function call was to ftell(), which can set errno */
        return 1;
    }
    return 0;
}

int test_noerrno_errno(void){
    noerrno();
    if (errno != 0) {   /* 'Inappropriate Test of Error Code' warning issued here
                         * - last function call was to noerrno(), which never sets errno
                         */
        return 1;
    }
    return 0;
}

int test_errno_path(FILE *fp, int i){
  if (i > 0){
    (void) ftell(fp);
  }
  else {
     noerrno();
  }
  if (errno != 0){      /* 'Inappropriate Test of Error Code' warning issued here
                         * - on paths where i<=0 the last function call was to noerrno(), which never sets errno
                         */
    return 1;
  }
  return 0;
}

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

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

 

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