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++
Binaries


ALLOC.TM : タイプミスマッチ

要旨

メモリ割り当てもしくは使用されたリソースが、それとは異なるタイプのリソースを解放もしくは使用する関数に渡されました。

ワーニングクラス名 注釈
タイプミスマッチ 異なるタイプのメモリ割り当てもしくは使用されたリソースが実引数として渡されました。
プールミスマッチ [Win32のみ] ヒープハンドルが渡されるべき関数に、それとは異なる実引数が渡されました。
LMEM_FIXEDメモリに対するロック
LMEM_FIXEDメモリに対するハンドル
LMEM_FIXEDメモリに対するアンロック
[Win32のみ] LMEM_FIXEDに割り当てられたローカルメモリオブジェクトに対して、ロック、アンロックもしくはハンドルを獲得しようとしました。
GMEM_FIXEDメモリに対するロック
GMEM_FIXEDメモリに対するハンドル
GMEM_FIXEDメモリに対するアンロック
[Win32のみ] GMEM_FIXEDに割り当てられたグローバルメモリオブジェクトに対して、ロック、アンロックもしくはハンドルを獲得しようとしました。

プロパティ

複数のワーニングクラスでこのニーモニックを共有しています。

これら全てのワーニングクラスのチェックはデフォルトで 有効になっています。チェックを全て無効にするには、プロジェクト設定ファ イル(configuration file)に以下の WARNING_FILTER ルールを追加し てください。

WARNING_FILTER += discard categories:ALLOC.TM
クラス名 GlobalHandle on GMEM_FIXED Memory
日本語クラス名 GMEM_FIXEDメモリに対するハンドル
クラス分類 信頼性 (reliability)
ニーモニック 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:686 Function Call With Incorrect Argument Type
  CWE:843 Access of Resource Using Incompatible Type ('Type Confusion')
CERT-C CERT-C:API07-C Enforce type safety
OWASP-2021 OWASP-2021:A4 Insecure design
OWASP-2025 OWASP-2025:A06 Insecure Design
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="GlobalHandle on GMEM_FIXED Memory"
クラス名 GlobalLock on GMEM_FIXED Memory
日本語クラス名 GMEM_FIXEDメモリに対するロック
クラス分類 信頼性 (reliability)
ニーモニック 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:686 Function Call With Incorrect Argument Type
  CWE:843 Access of Resource Using Incompatible Type ('Type Confusion')
CERT-C CERT-C:API07-C Enforce type safety
OWASP-2021 OWASP-2021:A4 Insecure design
OWASP-2025 OWASP-2025:A06 Insecure Design
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="GlobalLock on GMEM_FIXED Memory"
クラス名 GlobalUnlock on GMEM_FIXED Memory
日本語クラス名 GMEM_FIXEDメモリに対するアンロック
クラス分類 信頼性 (reliability)
ニーモニック 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:686 Function Call With Incorrect Argument Type
  CWE:843 Access of Resource Using Incompatible Type ('Type Confusion')
CERT-C CERT-C:API07-C Enforce type safety
OWASP-2021 OWASP-2021:A4 Insecure design
OWASP-2025 OWASP-2025:A06 Insecure Design
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="GlobalUnlock on GMEM_FIXED Memory"
クラス名 LocalHandle on LMEM_FIXED Memory
日本語クラス名 LMEM_FIXEDメモリに対するハンドル
クラス分類 信頼性 (reliability)
ニーモニック 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:686 Function Call With Incorrect Argument Type
  CWE:843 Access of Resource Using Incompatible Type ('Type Confusion')
CERT-C CERT-C:API07-C Enforce type safety
OWASP-2021 OWASP-2021:A4 Insecure design
OWASP-2025 OWASP-2025:A06 Insecure Design
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="LocalHandle on LMEM_FIXED Memory"
クラス名 LocalLock on LMEM_FIXED Memory
日本語クラス名 LMEM_FIXEDメモリに対するロック
クラス分類 信頼性 (reliability)
ニーモニック 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:686 Function Call With Incorrect Argument Type
  CWE:843 Access of Resource Using Incompatible Type ('Type Confusion')
CERT-C CERT-C:API07-C Enforce type safety
OWASP-2021 OWASP-2021:A4 Insecure design
OWASP-2025 OWASP-2025:A06 Insecure Design
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="LocalLock on LMEM_FIXED Memory"
クラス名 LocalUnlock on LMEM_FIXED Memory
日本語クラス名 LMEM_FIXEDメモリに対するアンロック
クラス分類 信頼性 (reliability)
ニーモニック 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:686 Function Call With Incorrect Argument Type
  CWE:843 Access of Resource Using Incompatible Type ('Type Confusion')
CERT-C CERT-C:API07-C Enforce type safety
OWASP-2021 OWASP-2021:A4 Insecure design
OWASP-2025 OWASP-2025:A06 Insecure Design
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="LocalUnlock on LMEM_FIXED Memory"
クラス名 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"
クラス名 Type Mismatch
日本語クラス名 タイプミスマッチ
クラス分類 セキュリティ (security)
ニーモニック ALLOC.TM
カテゴリー
MisraC2025 MisraC2025:1.3 There shall be no occurrence of undefined or critical unspecified behaviour
  MisraC2025:22.2 A block of memory shall only be freed if it was allocated by means of a Standard Library function
  MisraC2025:D.4.1 Run-time failures shall be minimized
MisraC2023 MisraC2023:1.3 There shall be no occurrence of undefined or critical unspecified behaviour
  MisraC2023:22.2 A block of memory shall only be freed if it was allocated by means of a Standard Library function
  MisraC2023:D.4.1 Run-time failures shall be minimized
Misra2012 Misra2012:1.3 There shall be no occurrence of undefined or critical unspecified behaviour
  Misra2012:22.2 A block of memory shall only be freed if it was allocated by means of a Standard Library function
  Misra2012:D.4.1 Run-time failures shall be minimized
AUTOSARC++14 AUTOSARC++14:A18-5-3 The form of the delete expression shall match the form of the new expression used to allocate the memory.
  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:590 Free of Memory not on the Heap
  CWE:686 Function Call With Incorrect Argument Type
  CWE:761 Free of Pointer not at Start of Buffer
  CWE:762 Mismatched Memory Management Routines
  CWE:843 Access of Resource Using Incompatible Type ('Type Confusion')
TS17961 TS17961:5.33-xfree Reallocating or freeing memory that was not dynamically allocated
CERT-C CERT-C:API07-C Enforce type safety
  CERT-C:MEM34-C Only free memory allocated dynamically
  CERT-C:WIN30-C Properly pair allocation and deallocation functions
CERT-CPP CERT-CPP:EXP51-CPP Do not delete an array through a pointer of the incorrect type
  CERT-CPP:MEM51-CPP Properly deallocate dynamically allocated resources
OWASP-2021 OWASP-2021:A4 Insecure design
OWASP-2025 OWASP-2025:A06 Insecure Design
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Type Mismatch"

各ワーニングの説明

タイプミスマッチ

メモリ割り当てもしくは使用されたリソースが、それとは異なるタイプのリソースを解放もしくは使用する関数に渡された場合、タイプミスマッチのワーニングを検出します。 This includes an attempt to free memory that was not allocated on the heap.

チェックされた関数/引数のペアは要求される引数の型により分類されます。 例えば fclose(FILE *stream)feof(FILE *stream) は両方とも FILE* 引数が要求されるため、同じ型ファミリーになります。

プールミスマッチ [Win32のみ]

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.

FIXEDメモリに関するワーニング [Win32のみ]

LMEM_FIXED もしくは GMEM_FIXED の特定の Win32API 関数に対してワーニングを検出します。

ワーニングクラス名 ワーニングを引き起こす関数 ワーニングが引き起こされる時
LMEM_FIXEDメモリに対するロック LocalLock()
LMEM_FIXEDメモリに対するハンドル LocalHandle()
LMEM_FIXEDメモリに対するアンロック LocalUnlock()
GMEM_FIXEDメモリに対するロック GlobalLock()
GMEM_FIXEDメモリに対するハンドル GlobalHandle()
GMEM_FIXEDメモリに対するアンロック GlobalUnlock()

#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; /* "Type Mismatch" warning issued here */
}

void free_stack_variable()
{
    char buf[10];
    char *q = &buf[0];
    free(q); /* "Type Mismatch" warning issued here */
}

void conflicting_types(void *p)
{
    (void)ftell((FILE*)p);
    (void)dlsym(p, "f"); /* "Type Mismatch" warning issued here -- p can't
                          * be both a FILE* and a dynamic shared object at
                          * the same time.
                          */
}

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); /* "Pool Mismatch" warning issued here; should have used pool1 */
    exit(0);
}

void conflicting_types_win32(HANDLE h)
{
    (void)GetThreadId(h);
    (void)GetFileSize(h, 0); /* "Type Mismatch" warning issued here --
                              * h can't be both a thread and a window
                              * at the same time.
                              */
    exit(0);
}

void ghandle(void)
{
    HGLOBAL x = GlobalAlloc(GMEM_FIXED, 16);
    if( x )
    {
        (void)GlobalHandle(x); // GlobalHandle on GMEM_FIXED Memory issued here
        (void)GlobalLock(x);   // GlobalLock on GMEM_FIXED Memory issued here
        (void)GlobalUnlock(x); // GlobalUnlock on GMEM_FIXED Memory issued here
    }
    exit(0);
}

void lhandle(void)
{
    HLOCAL x = LocalAlloc(LMEM_FIXED, 16);
    if( x )
    {
        (void)LocalHandle(x); // LocalHandle on LMEM_FIXED Memory issued here
        (void)LocalLock(x);   // LocalLock on LMEM_FIXED Memory issued here
        (void)LocalUnlock(x); // LocalUnlock on LMEM_FIXED Memory issued here
    }
    exit(0);
}

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

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

 

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