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.0p0 Hot Tips | CONFIDENTIAL | CodeSecure Inc |
整数定数表現 C は以下のいずれかに該当するとき、ポインタへ強制変換されます。
NULL の定義が整数定数表現(ポインタ型へのキャストがない)の場合、 NULL を使用している箇所でこのクラスのワーニングが検出されます。例えば:
#define NULL 0
void irreg_null(void){
int *p = NULL; /* 'Coercion: Integer Constant to Pointer' warning issued here */
}
(通常の定義の #define NULL ((void *)0)が使用されているときは、この箇所ではワーニングは検出されません。)
| クラス名 | Coercion: Integer Constant to Pointer | |||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 日本語クラス名 | 整数定数からポインタへの強制型変換 | |||||||||||||||||||||||||||||||||
| クラス分類 | スタイル (style) | |||||||||||||||||||||||||||||||||
| ニーモニック | LANG.CAST.PC.CONST2PTR | |||||||||||||||||||||||||||||||||
| カテゴリー |
|
|||||||||||||||||||||||||||||||||
| 対応言語 | C および C++ で利用可能です。 |
|||||||||||||||||||||||||||||||||
| 有効/無効設定 | このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST
が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと
RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes WARNING_FILTER += allow class="Coercion: Integer Constant to Pointer" |
#include <stdlib.h>
#define ZERO 0
void use_pointers(int *x, int *y, int *z);
int const2ptrs(int i, int *ptr){
int y = 0;
int *p1;
int *p2;
int *p3;
if (ptr == 0){return 0;} /* 'Coercion: Integer Constant to Pointer' warning issued here */
p1 = NULL; /* macro NULL (standard definition) */
p2 = 0; /* 'Coercion: Integer Constant to Pointer' warning issued here */
p3 = (int *) 0; /* explicit cast (not coercion) */
use_pointers(p1,p2,p3);
p1 = 0x080484e2; /* 'Coercion: Integer Constant to Pointer' warning issued here */
p2 = (i - y) ? ptr : 0; /* 'Coercion: Integer Constant to Pointer' warning issued here */
p3 = (i > y) ? 0 : ptr; /* 'Coercion: Integer Constant to Pointer' warning issued here */
use_pointers(p1,p2,p3);
p1 = y; /* not a constant expression */
p2 = i; /* not a constant expression */
p3 = ZERO; /* 'Coercion: Integer Constant to Pointer' warning issued here */
use_pointers(p1,p2,p3);
int a = (i - y) ? ptr : 0; /* 'Coercion: Integer Constant to Pointer' warning issued here */
int b = (i > y) ? 0 : ptr; /* 'Coercion: Integer Constant to Pointer' warning issued here */
return a+b;
}
設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。