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 |
NULLを指すポインタを間接参照しようとしています。
デフォルトでは、ゼロページ(0から4096までのアドレス)を指すポインタを間接参照しようとすると、このワーニングを検出します。 プロジェクト設定ファイル (configuration file) の NULL_POINTER_THRESHOLD パラメータで、このしきい値を変更出来ます。
| クラス名 | Null Pointer Dereference | |||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 日本語クラス名 | NULLポインタ参照 | |||||||||||||||||||||||||||||||||||||||||||||
| クラス分類 | 信頼性 (reliability) | |||||||||||||||||||||||||||||||||||||||||||||
| ニーモニック | LANG.MEM.NPD | |||||||||||||||||||||||||||||||||||||||||||||
| カテゴリー |
|
|||||||||||||||||||||||||||||||||||||||||||||
| 対応言語 | C および C++ で利用可能です。 |
|||||||||||||||||||||||||||||||||||||||||||||
| 有効/無効設定 | このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル
(configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Null Pointer Dereference" |
| CWE:400 | Uncontrolled Resource Consumption |
|---|
#include <stddef.h>
char lang_mem_npd_simple(void){
char *p = NULL;
return p[0]; /* 'Null Pointer Dereference' warning issued here */
}
char lang_mem_npd_with_aliasing(int x){
char *p1 = NULL;
char *p2;
char c;
if (x < 0){
p2 = "012345678";
}
else {
p2 = p1; /* 'Unused Value' warning issued here
* - this value of p2 is only used in a statement
* that causes a program crash (via Null Pointer Dereference),
* so CodeSonar considers it unused.
*/
}
c = p2[0];
return c; /* 'Null Pointer Dereference' warning issued here */
}
char * lang_mem_npd_with_malloc(void){
char *p = malloc(10);
p[0] = 'X'; /* 'Null Pointer Dereference' warning issued here
* only when MALLOC_FAILURE_BEHAVIOR=RETURN_NULL (factory setting)
*/
return p;
}
デフォルトで、 NULLポインタ参照は以下のような場合で検出されます。
char *q = malloc(10); /* malloc() can fail and return NULL */ q[0] = 'a'; /* in which case a Null Pointer Dereference occurs here */
malloc() および関連したアロケータは、失敗したとき NULL を返す可能性があります。 しかしながら、失敗する可能性が無視できるほど低い場合にはこれをチェックしたくない場合もあります。
これらのアロケータが決して失敗しないものとみなす場合には、 general configuration file template で MALLOC_FAILURE_BEHAVIOR=DOESNT_FAIL を設定してください。
MALLOC_FAILURE_BEHAVIOR の設定は全ての解析に影響することに注意してください。例えば、以下のコードでは MALLOC_FAILURE_BEHAVIOR=DOESNT_FAIL で解析された場合、 else ブロックの中のコードは到達不能とみなされます。
char *q = malloc(10);
if (q){
/* do something */
}
else {
/* do something different */
}
設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。