I'm trying to get my code clang-tidy clean, and it's complaining that I'm using garbage values.
I have some data stored as words, and I want to use it byte by byte.
clang-tidy doesn't seem to identify the array size post c-style cast.
A minimal example:
#include <stdio.h>
int main(void) {
int words[2] = { 123456789, 987654321 };
char* bytes = (char*)words;
printf("%d\n", bytes[1] * 2);
return 0;
}
The error:
/home/ce/example.c:7:27: warning: The left operand of '*' is a garbage value [clang-analyzer-core.UndefinedBinaryOperatorResult]
printf("%d\n", bytes[1] * 2);
^
/home/ce/example.c:7:27: note: The left operand of '*' is a garbage value
Note: I'm using c99