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.MO : 不整列なオブジェクト

要旨

動的にメモリ割り当てされたリソースを使用もしくは解放する関数が、割り当てられたリソースの開始位置以外のポインタを引数に呼ばれています。

プロパティ

クラス名 Misaligned Object
日本語クラス名 不整列なオブジェクト
クラス分類 セキュリティ (security)
ニーモニック ALLOC.MO
カテゴリー
MisraC++2023 MisraC++2023:0.3.2 A function call shall not violate the function's preconditions
CWE CWE:664 Improper Control of a Resource Through its Lifetime
  CWE:761 Free of Pointer not at Start of Buffer
  CWE:763 Release of Invalid Pointer or Reference
  CWE:823 Use of Out-of-range Pointer Offset
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで有効になっています。チェックを無効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += discard class="Misaligned Object"

ワーニングを引き起こす関数

CodeSonar ships with library models that allow it to a large number of functions that use or release a dynamically-allocated resource, across many different libraries. If one of these functions is called with a pointer argument that does not point to the beginning of the allocated object, 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 Misaligned Object warnings.

Functions that can trigger warnings include...
Apache Portable Runtime (APR) apr_palloc(), apr_pstrcat()
C++ operators operator delete()
FreeRTOS vQueueDelete()
gcc Builtins __builtin___fprintf_chk(), __builtin_fputc()
LDAP ldap_msgfree()
libc fgetc(), kvm_close()
Linux Kernel free_page(), kfree_()
Mac OS X _FREE(), thread_deallocate()
Nucleus DMCE_Deallocate_Memory(), PMCE_Delete_Partition_Pool()
OpenSSL CRYPTO_free(), CRYPTO_realloc()
Qt qFree(), qRealloc()
VxWorks lstFree(), semDelete()
Win32 CloseHandle(), fscanf_s()

#include <stdlib.h>

void misaligned_object(void){
    char * p = malloc( 10 );
    if (!p){
        return;
    }
    free(p + 1);  /* 'Misaligned Object' warning issued here */
}

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

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

 

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