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 |
An integer constant expression C is coerced to a pointer by being used in one of the following contexts.
Note that if your definition of NULL is an integer constant expression (without cast to pointer type), using NULL in these contexts will trigger warnings of this class. For example:
#define NULL 0
void irreg_null(void){
int *p = NULL; /* 'Coercion: Integer Constant to Pointer' warning issued here */
}
(A warning would not be issued in this location if the code used the more typical #define NULL ((void *)0).)
| Class Name | Coercion: Integer Constant to Pointer | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Significance | style | ||||||||||||||||||||||||||||||||||||
| Mnemonic | LANG.CAST.PC.CONST2PTR | ||||||||||||||||||||||||||||||||||||
| Categories |
|
||||||||||||||||||||||||||||||||||||
| Availability | Available for C and C++. |
||||||||||||||||||||||||||||||||||||
| Enabling | Checks for this warning class are disabled by default,
and require the unnormalized
C ASTs for the project. To enable them, add the following
WARNING_FILTER rule and RETAIN_UNNORMALIZED_C_AST specification to the project configuration file.
RETAIN_UNNORMALIZED_C_AST = Yes WARNING_FILTER += allow class="Coercion: Integer Constant to Pointer" |
#include <stdlib.h>
#define ZERO 0
void use_pointers(int *x, int *y, int *z);
int const2ptrs(int i, int *ptr){
int y = 0;
int *p1;
int *p2;
int *p3;
if (ptr == 0){return 0;} /* 'Coercion: Integer Constant to Pointer' warning issued here */
p1 = NULL; /* macro NULL (standard definition) */
p2 = 0; /* 'Coercion: Integer Constant to Pointer' warning issued here */
p3 = (int *) 0; /* explicit cast (not coercion) */
use_pointers(p1,p2,p3);
p1 = 0x080484e2; /* 'Coercion: Integer Constant to Pointer' warning issued here
* ('Incompatible Assignment Operands' and 'Nonzero Integer Conversion to Pointer'
* warnings also issued)
*/
p2 = (i - y) ? ptr : 0; /* 'Coercion: Integer Constant to Pointer' warning issued here */
p3 = (i > y) ? 0 : ptr; /* 'Coercion: Integer Constant to Pointer' warning issued here */
use_pointers(p1,p2,p3);
p1 = y; /* not a constant expression ('Incompatible Assignment Operands' warning issued) */
p2 = i; /* not a constant expression ('Incompatible Assignment Operands' warning issued) */
p3 = ZERO; /* 'Coercion: Integer Constant to Pointer' warning issued here */
use_pointers(p1,p2,p3);
int a = (i - y) ? ptr : 0; /* 'Coercion: Integer Constant to Pointer' warning issued here
* ('Bad Initializer Type' warning also issued)
*/
int b = (i > y) ? 0 : ptr; /* 'Coercion: Integer Constant to Pointer' warning issued here
* ('Bad Initializer Type' warning also issued)
*/
return a+b;
}
The following configuration file parameters affect checks for this warning class.
To report problems with this documentation, please visit https://support.codesecure.com/.