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

--- Comment #3 from Drea Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Alexey.Shinkin from comment #2)
> (In reply to Drea Pinski from comment #1)
> > Your conditions are swapped so you get undefined behavior when i is
> > MAX_ITEMS with an out of bounds access.
> 
>  Got it, thanks.
> 
>  Tricky though, no compiler warnings, works with -O1. 
>  But yeah, that is what UB is ...

-fsanitize=undefined will detect this case too:
/app/example.c:23:21: runtime error: index 10 out of bounds for type '<unknown>
[10]'

Reply via email to