public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/59933] New: for loop goes wild with assert() enabled
@ 2014-01-24 12:56 warnerme at ptd dot net
  2014-01-24 13:00 ` [Bug c/59933] " warnerme at ptd dot net
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: warnerme at ptd dot net @ 2014-01-24 12:56 UTC (permalink / raw)
  To: gcc-bugs

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.


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2014-02-20  1:00 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-24 12:56 [Bug c/59933] New: for loop goes wild with assert() enabled warnerme at ptd dot net
2014-01-24 13:00 ` [Bug c/59933] " warnerme at ptd dot net
2014-01-29 12:25 ` ian at g0tcd dot com
2014-01-29 13:14 ` ian at g0tcd dot com
2014-02-19  8:36 ` mpolacek at gcc dot gnu.org
2014-02-19 12:27 ` warnerme at ptd dot net
2014-02-19 14:08 ` warnerme at ptd dot net
2014-02-19 14:54 ` mpolacek at gcc dot gnu.org
2014-02-19 15:49 ` jakub at gcc dot gnu.org
2014-02-19 16:12 ` ian at g0tcd dot com
2014-02-19 16:41 ` jakub at gcc dot gnu.org
2014-02-19 20:57 ` jakub at gcc dot gnu.org
2014-02-20  1:00 ` ian at g0tcd dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).