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 |
The value returned by one of the following functions is treated as if it is not a pointer to const-qualified type.
| Class Name | Returned Pointer Not Treated as const | ||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | security | ||||||||||||||||||
| Mnemonic | LANG.STRUCT.RPNTC | ||||||||||||||||||
| Categories |
|
||||||||||||||||||
| Availability | Available for C and C++. |
||||||||||||||||||
| Enabling | Checks for this warning class are
disabled by default. To enable them, add the following WARNING_FILTER
rule to the project configuration file.
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) */ }
The following configuration file parameters affect checks for this warning class.
To report problems with this documentation, please visit https://support.codesecure.com/.