https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108770

--- Comment #6 from Andrew Teylu <andrew.teylu at vector dot com> ---
Apologies for not testing this; I tried it on godbolt and got:

```
<source>: In function 'init':
<source>:10:13: error: array subscript 2 is above array bounds of 'const char
*[2]' [-Werror=array-bounds=]
   10 |   while (arr[check_idx(i)] != 0) {
      |          ~~~^~~~~~~~~~~~~~
<source>:7:13: note: while referencing 'arr'
    7 | const char *arr[] = {"A", 0};
      |             ^~~
cc1: all warnings being treated as errors
Compiler returned: 1
```

I'd just like to clarify what @qinzhao wrote:

> I think that the original code has a bug
>

Could you help me understand where the bug is in this code? Not trying to be
difficult, I am genuinely curious.

My reading of this code is that the loop only executes twice: once for 0 (when
the arr access gives 'A'), and then then i is 1, the loop terminates. This
means it never executes the loop when i is 2.

Basically, I am not sure it is correct to say this is fixed, as I still feel
this is a false positive on the warning.

Reply via email to