HP Code Advisor Diagnostics

Action:
Ensure that all elements/fields of an array/struct are unconditionally initialized prior to accessing
them.
Reference:
20074 variable %s (field "%s") may be used before its value is set
Cause:
A field of a struct may be referenced prior to its initialization.
Example:
struct A {
int a;
int b;
};
struct A a;
a.a = 10;
if (cond)
a.b = 12;
foo(a); // warning 20074: field b of struct a may
// be uninitialized.
Action:
Ensure that all fields of a struct are unconditionally initialized prior to accessing them.
Reference:
20200 Potential null pointer dereference %s%s is detected %s
Cause:
A reference through a pointer whose value may be null has been detected. The pointer could
have been conditionally initialized or assigned with the return value of a function that may return
NULL.
Example:
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
void nullptr3 ()
{
char *p = malloc (20); // LINE 6
strcpy (p, "nullptr3");
FILE* f = fopen("blah","r"); // LINE 8
if (p != NULL)
fread(p,20,1,f);
printf ("%s", p);
}
"file1.c", line 7, procedure nullptr3: warning #file1-D: Potential null
pointer dereference through p is detected (null definition:file1.c,
line 6)
"file1.c", line 10, procedure nullptr3: warning #file1-D: Potential null
pointer dereference through f is detected (null definition:file1.c,
line 8)
Action:
If you are assigning NULL to a pointer, make sure that no path in the program can dereference
that pointer before it is assigned a different value. For routines that may return a NULL, check
or assert that the value returned is not NULL. char * pc = malloc(20); if (pc != NULL) strcpy(pc,
"hello"); or: char * pc = malloc(20); assert(pc != NULL); strcpy(pc, "hello");
Reference:
20074 variable %s (field "%s") may be used before its value is set 75