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


LANG.TYPE.IARGT.MEMCMP : Inappropriate Argument to memcmp

要旨

A call to memcmp() where the type of one or both pointer arguments is not "pointer to X" with X one of the following.

See MISRA Checks: Essential Type Category for more information.

プロパティ

クラス名 Inappropriate Argument to memcmp
日本語クラス名 Inappropriate Argument to memcmp
クラス分類 スタイル (style)
ニーモニック LANG.TYPE.IARGT.MEMCMP
カテゴリー
MisraC2025 MisraC2025:21.16 The pointer arguments to the Standard Library function memcmp shall point to either a pointer type, an essentially signed type, an essentially unsigned type, an essentially Boolean type or an essentially enum type
MisraC2023 MisraC2023:21.16 The pointer arguments to the Standard Library function memcmp shall point to either a pointer type, an essentially signed type, an essentially unsigned type, an essentially Boolean type or an essentially enum type
Misra2012 Misra2012:21.16 The pointer arguments to the Standard Library function memcmp shall point to either a pointer type, an essentially signed type, an essentially unsigned type, an essentially Boolean type or an essentially enum type
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっており、プロジェクトには非正規の C向けAST が必要になります。有効にするにはプロジェクト設定ファイル (configuration file) に以下の WARNING_FILTER ルールと RETAIN_UNNORMALIZED_C_AST 設定を追加してください。
RETAIN_UNNORMALIZED_C_AST = Yes
WARNING_FILTER += allow class="Inappropriate Argument to memcmp"
注:非正規化された AST を継続して使用した場合、使用ディスク容量が増加し解析時間が長くなる可能性があります。

#include <string.h>

typedef struct { int color; } S;

int lang_type_iargt_bad(const float *f1, const float *f2,
                        S *s1,  S *s2, size_t sn,
                        const void *v1, const void *v2, size_t n
                       ){
    if (!memcmp(f1, f2, sizeof(float))){ /* 'Inappropriate Argument to memcmp' warning issued here
                                          * - pointed-to type for f1 and f2 is 'float', which
                                          *   is not one of the types permitted for this warning class.
                                          * - There are two warning instances (one for each pointer
                                          *   argument), in the same warning group.
                                          */
        return 0;
    }
    if (!memcmp(s1, s2, sn)){            /* 'Inappropriate Argument to memcmp' warning issued here
                                          * - pointed-to type for s1 and s2 is 'S' (a struct type)
                                          * - There are two warning instances, in the same warning group.
                                          */
        return 0;
    }
    if (!memcmp(v1, v2, n)) {            /* 'Inappropriate Argument to memcmp' warning issued here
                                          * -pointed-to type for v1 and v2 is 'void'
                                          * - There are two warning instances, in the same warning group.
                                          */
        return 0;
    }
    return 1;
}

int lang_type_iargt_ok(int *i1, int *i2, size_t sz){
    if (!memcmp(i1, i2, sizeof(int))){ return 0; } /* ok: pointed-to type for i1 and i2 is 'int',
                                                    * which is an essentially signed type */
    if (!memcmp(&i1, &sz, sz)){ return 0; }        /* ok: pointed-to types are as follows
                                                    * - &i1: int* (pointer type)
                                                    * - &sz: size_t (essentially unsigned)
                                                   */
    return 1;
}

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

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

 

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