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.
-
If you access the manual through the hub's Web GUI, the
functionality will not be suppressed because the hub is a web
server.
-
Alternatively, your browser may allow you to explicitly
disable the security setting that suppresses functionality. See
the CodeSonar
FAQ for more information.
ALLOC.TM : タイプミスマッチ
メモリ割り当てもしくは使用されたリソースが、それとは異なるタイプのリソースを解放もしくは使用する関数に渡されました。
複数のワーニングクラスでこのニーモニックを共有しています。
これら全てのワーニングクラスのチェックはデフォルトで
有効になっています。チェックを全て無効にするには、プロジェクト設定ファ
イル(configuration
file)に以下の WARNING_FILTER ルールを追加し
てください。
WARNING_FILTER += discard categories:ALLOC.TM
| クラス名 |
Pool Mismatch |
| 日本語クラス名 |
プールミスマッチ |
| クラス分類 |
セキュリティ (security) |
| ニーモニック |
ALLOC.TM |
| カテゴリー |
| AUTOSARC++14 |
AUTOSARC++14:A18-5-5 |
Memory management functions shall ensure the following: (a) deterministic behavior resulting with the existence of worst-case execution time, (b) avoiding memory fragmentation, (c) avoid running out of memory, (d) avoiding mismatched allocations or deallocations, (e) no dependence on non-deterministic calls to kernel. |
| MisraC++2023 |
MisraC++2023:0.3.2 |
A function call shall not violate the function's preconditions |
| CWE |
CWE:762 |
Mismatched Memory Management Routines |
| CERT-C |
CERT-C:API07-C |
Enforce type safety |
| |
CERT-C:WIN30-C |
Properly pair allocation and deallocation functions |
|
| 対応言語 |
C および C++ で利用可能です。
|
| 有効/無効設定 |
このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル
(configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Pool Mismatch"
|
各ワーニングの説明
メモリ割り当てもしくは使用されたリソースが、それとは異なるタイプのリソースを解放もしくは使用する関数に渡された場合、タイプミスマッチのワーニングを検出します。
This includes an attempt to free
memory that was not allocated on the heap.
チェックされた関数/引数のペアは要求される引数の型により分類されます。 例えば fclose(FILE
*stream) と feof(FILE
*stream) は両方とも FILE*
引数が要求されるため、同じ型ファミリーになります。
CodeSonar ships with library models that allow it to functions such as Win32 HeapFree() that must be called with compatible heap handle and pointer arguments.
If one of these functions is called with incompatible arguments, a warning will be issued.
If you have created a custom library model
for some function f() in terms of one of
these existing models, calls to f() will also be capable of
triggering Pool Mismatch warnings.
LMEM_FIXED もしくは GMEM_FIXED の特定の Win32API
関数に対してワーニングを検出します。
#include <stdlib.h>
#include <stdio.h>
#include <dlfcn.h>
#include <windows.h>
void mix_malloc_delete()
{
char *p = (char*)malloc( 10 );
if( p )
delete[] p;
}
void free_stack_variable()
{
char buf[10];
char *q = &buf[0];
free(q);
}
void conflicting_types(void *p)
{
(void)ftell((FILE*)p);
(void)dlsym(p, "f");
}
void wrong_pool()
{
HANDLE pool1 = HeapCreate(0, 0, 1024*1024);
HANDLE pool2 = HeapCreate(0, 0, 1024*1024);
LPVOID ha = pool1 ? HeapAlloc(pool1, 0, 5) : NULL;
if( pool2 && ha )
(void)HeapFree(pool2, 0, ha);
exit(0);
}
void conflicting_types_win32(HANDLE h)
{
(void)GetThreadId(h);
(void)GetFileSize(h, 0);
exit(0);
}
void ghandle(void)
{
HGLOBAL x = GlobalAlloc(GMEM_FIXED, 16);
if( x )
{
(void)GlobalHandle(x);
(void)GlobalLock(x);
(void)GlobalUnlock(x);
}
exit(0);
}
void lhandle(void)
{
HLOCAL x = LocalAlloc(LMEM_FIXED, 16);
if( x )
{
(void)LocalHandle(x);
(void)LocalLock(x);
(void)LocalUnlock(x);
}
exit(0);
}
設定ファイルの以下のパラメータがこのワーニングクラスのチェックに影響します。