public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/31287]  New: Infinite for loop while initializing char array
@ 2007-03-20 20:58 bryan_sauser at pa-ucl dot com
  2007-03-20 21:01 ` [Bug c++/31287] " pinskia at gcc dot gnu dot org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: bryan_sauser at pa-ucl dot com @ 2007-03-20 20:58 UTC (permalink / raw)
  To: gcc-bugs

I have a simple for for loop that initializes a char array and never stops.
Here is a small sample program that simulated the problem.

#include <stdio.h>

int main(int argc, char *argv[]){

   int i=0;
   char     name_array[7][100];

   for (i=0; i <= 7; i++)
   {
      printf("Loop i: %d\n", i);
      name_array[i][0] = '\0';
   }

   return 1;
}


Here are my compile options

g++ -o testloop testloop.cpp

Example of the output

Loop i: 1
Loop i: 2
Loop i: 3
Loop i: 4
Loop i: 5
Loop i: 6
Loop i: 7
Loop i: 1
Loop i: 2
Loop i: 3
Loop i: 4
Loop i: 5
Loop i: 6
Loop i: 7
Loop i: 1
Loop i: 2
Loop i: 3
Loop i: 4
Loop i: 5
Loop i: 6


-- 
           Summary: Infinite for loop while initializing char array
           Product: gcc
           Version: 4.1.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: bryan_sauser at pa-ucl dot com


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


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

* [Bug c++/31287] Infinite for loop while initializing char array
  2007-03-20 20:58 [Bug c++/31287] New: Infinite for loop while initializing char array bryan_sauser at pa-ucl dot com
@ 2007-03-20 21:01 ` pinskia at gcc dot gnu dot org
  2007-03-20 21:03 ` bryan_sauser at pa-ucl dot com
  2007-03-20 21:27 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-03-20 21:01 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pinskia at gcc dot gnu dot org  2007-03-20 21:01 -------
Note you are going over name_array's bounds so you are invoking undefined
behavior.  7 <= 7. arrays go from 0 to last-1 in C or (0, last-1] in math
notation for C arrays.


-- 


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


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

* [Bug c++/31287] Infinite for loop while initializing char array
  2007-03-20 20:58 [Bug c++/31287] New: Infinite for loop while initializing char array bryan_sauser at pa-ucl dot com
  2007-03-20 21:01 ` [Bug c++/31287] " pinskia at gcc dot gnu dot org
@ 2007-03-20 21:03 ` bryan_sauser at pa-ucl dot com
  2007-03-20 21:27 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: bryan_sauser at pa-ucl dot com @ 2007-03-20 21:03 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from bryan_sauser at pa-ucl dot com  2007-03-20 21:03 -------
Was code given to me by Contract programmer. Released person simple mistake
after reviewing.


-- 

bryan_sauser at pa-ucl dot com changed:

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


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


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

* [Bug c++/31287] Infinite for loop while initializing char array
  2007-03-20 20:58 [Bug c++/31287] New: Infinite for loop while initializing char array bryan_sauser at pa-ucl dot com
  2007-03-20 21:01 ` [Bug c++/31287] " pinskia at gcc dot gnu dot org
  2007-03-20 21:03 ` bryan_sauser at pa-ucl dot com
@ 2007-03-20 21:27 ` pinskia at gcc dot gnu dot org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-03-20 21:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pinskia at gcc dot gnu dot org  2007-03-20 21:26 -------
*** Bug 31288 has been marked as a duplicate of this bug. ***


-- 


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


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

end of thread, other threads:[~2007-03-20 21:27 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-03-20 20:58 [Bug c++/31287] New: Infinite for loop while initializing char array bryan_sauser at pa-ucl dot com
2007-03-20 21:01 ` [Bug c++/31287] " pinskia at gcc dot gnu dot org
2007-03-20 21:03 ` bryan_sauser at pa-ucl dot com
2007-03-20 21:27 ` pinskia at gcc dot gnu dot org

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).