HP Code Advisor Diagnostics

20208 Forming out of bound address(%s)
Cause:
The expression is forming an address which is out of object's memory boundary.
Example:
char buf[12];
char *p;
void foo()
{
int i = 20;
p = &buf[0] + i; // LINE 7
}
line 7, procedure foo: warning #20208-D: Forming out of bound
address (In expression "&buf[0]+20", variable "buf" [test.c:1]
(type: char [12]) has byte range [0 .. 11], forming address byte
[20].)
Action:
Fix the forming out of bounds access if it is a real bug.
Reference:
20210 Mismatch in allocation and deallocation
Cause:
The compiler has detected a code that uses different methods for memory allocation and it's
corresponding deallocation. A memory allocated using malloc() and it's variations should be
deallocated only by using free() and memory allocated using new operator should be deallocated
only by using delete. Memory allocated using alloca() should not be deallocated using either
free() or delete.
Example:
1 #include
2 #include
3
4 char* allocate()
5 {
6 return (char*)malloc(sizeof(char)*100);
7 }
8
9 void xyz()
10 {
11 char *str = allocate();
12 delete str;
13 }
"20210.C", line 12, procedure xyz: warning #20210-D: Mismatch in allocation
and deallocation
Action:
Replace the deallocator function call/operation with the one corresponding to the allocator or
the vice versa.
Reference:
20213 Potential write to read only memory %s%s is detected
Cause:
The code is trying to modify an area of the memory that has been defined as read-only.
Example:
#include <stdlib.h>
#include <stdio.h>
const char * astring = "foo";
78 Diagnostics Details