http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59933

            Bug ID: 59933
           Summary: for loop goes wild with assert() enabled
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: warnerme at ptd dot net

I have this odd case where a for loop goes wild.
But it only fails when assert() is enabled.

gcc  -Iinc -g -O2 -DDEBUG -fstack-protector-all -W -Wstrict-prototypes -Wall
-Wextra -Wcast-align -Wnested-externs -Wshadow -c -o build/NSQ_del_dec.o
c/NSQ_del_dec.c

If -DNDEBUG is used, the code works fine, although there is a slight difference
between CYGWIN32 (4.8.2-2) and CYGWIN64 (4.8.2-1).  This was not a problem with
gcc 4.7.

        if (RDmin_Q10 < RDmax_Q10)
        {
#if 1
            /* THIS IS THE CODE THAT FAILS */
            for (k = i; k < (int)(sizeof(NSQ_del_dec_struct) /
sizeof(opus_int32)); ++k)
            {
                psDelDec[RDmax_ind].sLPC_Q14[k] =
psDelDec[RDmin_ind].sLPC_Q14[k];
            }
#else
            /* THIS IS THE WORK-AROUND */
            int n = (sizeof(NSQ_del_dec_struct) / sizeof(opus_int32)) - i;
            opus_int32 *src = &psDelDec[RDmin_ind].sLPC_Q14[i];
            opus_int32 *dst = &psDelDec[RDmax_ind].sLPC_Q14[i];
            while (n-- > 0)
                *dst++ = *src++;
#endif
            psSampleState[RDmax_ind][0] = psSampleState[RDmin_ind][1];
        }

I've tried lots of combinations of code to get the work around, and this even
fails when I insert printf-s, but the most common with this exact code is that
it does sizeof(NSQ_del_dec_struct) number of loops leaving out the /
sizeof(opus_int32).  I have had some test test where the loop didn't stop till
it destroyed enough stack to crash it.

Sorry, that the file is a bit big but trying to whittle it down usually made
the problem go away.

Reply via email to