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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Sayu from comment #3)
> (In reply to Andrew Pinski from comment #1)
> > N could be -1 which then would access out of bounds ..
> > 
> > I suspect if you add a check for n being negative in memoized_cut_rod the
> > warning will go away and a security issue is solved too.
> 
> I see. I didn't realize that negative indexes are allowed in C, I always
> assumed it was undefined behavior or just invalid. However, what does "*r_30
> + _122" mean in the warning?

well for pointers it is not undefined. Just in this case it is being allocated
via malloc which does make it undefined. But that is the whole reason for the
warning.

The trunk gives:
In function 'memoized_cut_rod_aux',
    inlined from 'memoized_cut_rod' at <source>:34:14:
<source>:5:10: warning: '*<unknown>' may be used uninitialized
[-Wmaybe-uninitialized]
    5 |     if (r[n] >= 0)
      |         ~^~~

Which was fixed by PR 111253 .

But yes this is warning about r being used as not being initialized in the case
n in memoized_cut_rod being negative and acessing r[n] here.

Reply via email to