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.STRUCT.RPNTC : Returned Pointer Not Treated as const

要旨

The value returned by one of the following functions is treated as if it is not a pointer to const-qualified type.

プロパティ

クラス名 Returned Pointer Not Treated as const
日本語クラス名 Returned Pointer Not Treated as const
クラス分類 セキュリティ (security)
ニーモニック LANG.STRUCT.RPNTC
カテゴリー
MisraC2025 MisraC2025:21.19 The pointers returned by the Standard Library functions localeconv, getenv, setlocale or strerror shall only be used as if they have pointer to const-qualified type
MisraC2023 MisraC2023:21.19 The pointers returned by the Standard Library functions localeconv, getenv, setlocale or, strerror shall only be used as if they have pointer to const-qualified type
Misra2012 Misra2012:21.19 The pointers returned by the Standard Library functions localeconv, getenv, setlocale or, strerror shall only be used as if they have pointer to const-qualified type
TS17961 TS17961:5.28-libmod Modifying the string returned by getenv, localeconv, setlocale, and strerror
CERT-C CERT-C:DCL00-C Const-qualify immutable objects
  CERT-C:ENV30-C Do not modify the object referenced by the return value of certain functions
対応言語 C および C++ で利用可能です。
有効/無効設定 このワーニングクラスのチェックはデフォルトで無効になっています。チェックを有効にするにはプロジェクト設定ファイル (configuration file)に以下の WARNING_FILTER ルールを追加してください。
WARNING_FILTER += allow class="Returned Pointer Not Treated as const"

#include <stdlib.h>
#include <string.h>

/*  The value of an environment variable can change, so getenv(name)
 *  for fixed name may have different values at different program
 *  points.
 */
char * lang_struct_rpntc(char *name, char str[128]){
  char *c;       
  const char *cc;
  
  c = getenv(name);        /* 'Returned Pointer Not Treated as const' warning issued here.
                            * The code does not subsequently mutate *c, but future changes could
                            * introduce a mutation without causing compilation errors.
                            * Use a const-qualified variable to prevent this.
                            */
  if (!c){return NULL;}
  cc = getenv(name);                       /* ok: const-qualified pointer type */
  if (!cc){return NULL;}
  
  getenv(name)[0] = 'X';   /* 'Returned Pointer Not Treated as const' warning issued here
                            * ('Null Pointer Dereference' warning also issued: getenv() may return NULL)
                            */ 

  return strncpy(str, getenv(name), 127);  /* no 'Returned Pointer Not Treated as const' warning
                                            * - strcpy type signature is
                                            * char *strncpy (char *, const char *, size_t)
                                            */
                            /* ('Null Pointer Dereference' warning issued: getenv() may return NULL) */ 
}

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

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

 

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