Sujet : Re: Two questions on arrays with size defined by variables
De : ifonly (at) *nospam* youknew.org (Opus)
Groupes : comp.lang.cDate : 10. Feb 2025, 02:44:26
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vobllr$tdqt$1@dont-email.me>
References : 1 2 3 4 5 6 7 8
User-Agent : Mozilla Thunderbird
On 09/02/2025 19:19, Michael S wrote:
On Sun, 9 Feb 2025 18:46:44 +0100
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
wrong! - assignment to 'a[99]' produced also no compiler complaints,
gcc produces warning in this case, but only at optimization level of 2
or higher.
Which version of gcc?
Tried with gcc 14.2 (x86-64) with -Wall -O3 (or -O2, same), it doesn't give any warning whatsoever. (And yes, same with clang.)
Cppcheck does spot it properly though:
error: Array 'arr[5]' accessed at index 99, which is out of bounds. [arrayIndexOutOfBounds]
arr[99] = "foobar";
I highly recommend using Cppcheck as a static analyzer (at the bare minimum, there are better out there). Compilers are pretty basic in terms of static analysis.