cppcheck

cppcheck: Array index out of bounds; 'buf' buffer size is 0 and it is accessed at offset 3. [ctuArrayIndex]


This is the full error:

Src/utils.c:243:23: error: Array index out of bounds; 'buf' buffer size is 0 and it is accessed at offset 3. [ctuArrayIndex]
    value = (uint32_t)buf[3] << 24u;
                      ^
Src/crypto/chacha20.c:87:41: note: Calling function Utils_Deserialize32LE, 1st argument is uninitialized
    uint32_t x4  = Utils_Deserialize32LE(&key[0]);
                                        ^
Src/utils.c:243:23: note: Using argument buf
    value = (uint32_t)buf[3] << 24u;
                      ^
make: *** [Makefile:178: cppcheck] Error 1

The code is here: https://github.com/IMProject/IMUtility/blob/pr-chacha20/Src/utils.c#L243

https://github.com/IMProject/IMUtility/blob/pr-chacha20/Src/crypto/chacha20.c#L87

The code works properly. It seems it is some guard but I am not sure how to cover it since it is not clear to me what is testing. Has anyone seen this before?

I've tried NULL_PTR checks.


Solution

  • It seems it was a bug in cppcheck v2.9 only, after I moved to 2.13.4 I didn't get this error anymore.