As **b points at the first element of a, we're obviously writing there, therefore it would be incorrect to put a into read-only memory. If I try to mark a as const char a[1][1], then cppcheck doesn't warn, but gcc rightfully does.
Interestingly the false warning disappears if I initialize b on the same line as char *b[1] = {a[0]};
Last edit: Siim Ainsaar 2022-06-22
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I analyzed the following file.
cppcheck 2.8 and also the current tip of the main branch give the following false error:
As
**b
points at the first element ofa
, we're obviously writing there, therefore it would be incorrect to puta
into read-only memory. If I try to marka
asconst char a[1][1]
, then cppcheck doesn't warn, but gcc rightfully does.Interestingly the false warning disappears if I initialize
b
on the same line aschar *b[1] = {a[0]};
Last edit: Siim Ainsaar 2022-06-22
Thanks for reporting, this PR fixes the issue: https://github.com/danmar/cppcheck/pull/4228