I am trying to get rid of violation rule 9.1 from my code.
Rule 9.1: The value of an object with automatic storage duration shall not be read before it has been set
Sample code:
#include <stdint.h>
#include <stdbool.h>
#define VAL 0xABCDEFABU
int32_t main(void);
static int32_t do_test(bool k);
static void func(uint64_t *var3, const uint64_t *var5);
int32_t
main (void)
{
bool b = false;
int32_t y = do_test(b);
return y;
}
static int32_t
do_test(bool k)
{
uint64_t i = 0, var4[10];
int32_t result = 0;
for(i = 0U; i < 10U; i++) {
var4[i] = VAL + i;
}
if(k == false) {
uint64_t var2[10];
func(var2, var4);
if(var2[9] == var4[9]) {
result = 1;
}
}
return result;
}
static void
func(uint64_t *var3, const uint64_t *var5)
{
int32_t i;
for(i = 0; i < 10; i++) {
var3[i] = var5[i];
}
}
I am initializing var2 in the function do_test by calling another function "func" where var4 is copied to var2.
It is compiling fine and I am getting y value = 1.
Is it the violation due to parameters in func as pointers and the function do_test is not getting aware about the value assignment through pointers in func
Is there anyway to fix this issue ?
var3orvar5initialized ? Isvar5[i]initialized ? Obviously no, so this doesn't violate the rule.main()is special in C, do not prototype it. use a return type ofint,var2. To initializevar2, useuint64_t var4[10] = { something };Anything after that is assignment.