HP-UX Cadvise Diagnostics Reference Guide (5900-1865, August 2012)

Table Of Contents
}
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";
const char * bstring = "bar";
void mod_astring()
{
char* w = (char*) astring;
*w = 'g'; // LINE 9
}
int x;
void mod_bstring()
{
char* s;
if (x == 11)
s = (char*) bstring;
else
{
20210 Mismatch in allocation and deallocation 77