C and C++ Binaries


BADFUNC.BSEARCH : bsearchの使用

要旨

環境によっては未定義動作となる bsearch() を使用しています。

プロパティ

クラス名 Use of bsearch
日本語クラス名 bsearchの使用
クラス分類 スタイル (style)
ニーモニック BADFUNC.BSEARCH
カテゴリー
MisraC2023 MisraC2023:21.9 The library functions bsearch and qsort of <stdlib.h> shall not be used
Misra2012 Misra2012:21.9 The library functions bsearch and qsort of <stdlib.h> shall not be used
CWE CWE:676 Use of Potentially Dangerous Function
  CWE:758 Reliance on Undefined, Unspecified, or Implementation-Defined Behavior
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっています。チェックを有効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += allow class="Use of bsearch"

int mycompfn (const void* a, const void *b);
int myarr[100];

int do_lookup(int i){
    void * res;
    res = bsearch ((void *)&i, &myarr, 100, sizeof(int), &mycompfn); /* 'Use of bsearch' warning issued here */
  if (!res){
    return -1;
  }
  return *(int*)res;
}      

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

このクラスは一般テンプレート設定ファイルで BAD_FUNCTION_* ルールセットによって実装されています。

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