...
In this code example, the second operand of the logical OR operator invokes a function that results in side effects.
Code Block | ||
---|---|---|
| ||
char *p = /* initialize, may or may not be NULL */ if (p || (p = (char *) malloc(BUF_SIZE)) ) { /* do stuff with p */ free(p); p = NULL; } else { /* handle malloc() error */ return; } |
Since Because malloc()
is 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 is partially due to the uncertainty of whether malloc()
is actually called or not.
...