HP Code Advisor Diagnostics

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
{
s = (char*) malloc(128);
if (s == 0) exit(1);
}
sprintf(s,"%d",x); // LINE 25
puts(s);
}
line 9, procedure mod_astring: warning #20213-D: Potential write to
readonly memory through astring is detected
line 25, procedure possible: warning #20213-D: Potential write to
readonly memory through s is detected
Action:
Look at the definition of the memory written to and make sure that it is not defined as "const".
Reference:
20229 variable "%s" is uninitialized if the loop %s is not executed
Cause:
This warning is issued by the compiler if a variable is initialized in the loop body. Initialization
of this variable depends on the loop execution.
Example:
#include<stdio.h>
int foo(int n)
{
int var;
for (int i=0; i<n; i++) {
var = i;
}
printf("var: %d\n", var);
return var;
}
int main()
{
foo(5);
return 0;
}
Action:
Ensure that all the elements declared before the loop are not initialized inside the loop.
Reference:
20231 variable "%s" (field "%s") may be used before its value is set if the
loop %s is not executed
Cause:
Example:
#include <stdio.h>
20229 variable "%s" is uninitialized if the loop %s is not executed 79