...
| Code Block |
|---|
enum { max = 15 };
int i = /* initializeInitialize to user supplied value */;
if ( (i >= 0) && ( (i++) <= max) ) {
/* codeCode */
}
|
Although the behavior is well defined, it is not immediately obvious whether or not i gets incremented.
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
char *p = /* initializeInitialize, may or may not be NULL */ if (p || (p = (char *) malloc(BUF_SIZE)) ) { /* doDo stuff with p */ free(p); p = NULL; } else { /* handleHandle malloc() error */ return; } |
Because malloc() is called only called if p is NULL when entering the if clause, free() might be called with a pointer to local data not allocated by malloc(). (See MEM34-C. Only free memory allocated dynamically.) This behavior is partially due to the uncertainty of whether or not malloc() is actually called.
...
| Code Block | ||||
|---|---|---|---|---|
| ||||
char *p;
char *q = NULL;
if (p == NULL) {
q = (char *) malloc(BUF_SIZE);
p = q;
}
if (p == NULL) {
/* handleHandle malloc() error */
return;
}
/* doDo stuff with p */
free(q);
q = NULL;
|
...
Tool | Version | Checker | Description | ||||||
|---|---|---|---|---|---|---|---|---|---|
|
| Could detect possible violations of this recommendation by reporting expressions with side effects, including function calls, that appear on the right-hand - side of an | |||||||
| 35 D | Fully implemented | |||||||
| PRQA QA-C |
| 3415 | Fully implemented |
...