public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/32786] New: Incorrect code compiles and runs well
@ 2007-07-17 2:23 bachmann dot matt at gmail dot com
2007-07-17 3:17 ` [Bug c++/32786] " pinskia at gcc dot gnu dot org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: bachmann dot matt at gmail dot com @ 2007-07-17 2:23 UTC (permalink / raw)
To: gcc-bugs
This is my first bug report... I am not quite sure what you mean by
host/target/build triplet so ill give you what I can
complied on an 686 architecture in linux.
#include<iostream>
#include<cstdlib>
using namespace std;
/**
* Matt Bachmann
* CS 331
* HW1 Due: July 9th 2007
* Main method shows different ways of traversing strings
*/
int main() {
char mary[25] = "Mary had a little lamb.";
char* moby = "Thar she blows!";
cout << strlen(mary) << endl << endl;
for(unsigned int i = 0; i < strlen(mary); i++) {
for(unsigned int a = i; a < strlen(mary); a++) {
cout << mary[a];
}
cout << endl;
}
cout << endl;
cout << strlen(moby) << endl << endl;
while(moby != '\0') {
cout << moby << endl;
moby++;
}
system("PAUSE");
return EXIT_SUCCESS;
}
the condition in the while loop should cause an infinite loop and should be
moby*
--
Summary: Incorrect code compiles and runs well
Product: gcc
Version: 4.1.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: bachmann dot matt at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32786
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/32786] Incorrect code compiles and runs well
2007-07-17 2:23 [Bug c++/32786] New: Incorrect code compiles and runs well bachmann dot matt at gmail dot com
@ 2007-07-17 3:17 ` pinskia at gcc dot gnu dot org
2007-07-17 3:39 ` bachmann dot matt at gmail dot com
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-07-17 3:17 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2007-07-17 03:17 -------
> the condition in the while loop should cause an infinite loop and should be
> moby*
I think you mean *moby. Anyways it is just undefined that you go past the
array bounds when incrementing a pointer so we know it will not be an infinite
loop and has a finite length.
Anyways the program crashes for me which is a valid behavior.
while(moby != '\0') {
This is valid as '\0' can be considered the NULL pointer.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32786
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/32786] Incorrect code compiles and runs well
2007-07-17 2:23 [Bug c++/32786] New: Incorrect code compiles and runs well bachmann dot matt at gmail dot com
2007-07-17 3:17 ` [Bug c++/32786] " pinskia at gcc dot gnu dot org
@ 2007-07-17 3:39 ` bachmann dot matt at gmail dot com
2007-07-17 3:58 ` pinskia at gcc dot gnu dot org
2007-07-17 4:04 ` bachmann dot matt at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: bachmann dot matt at gmail dot com @ 2007-07-17 3:39 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from bachmann dot matt at gmail dot com 2007-07-17 03:39 -------
but thats just it! alright it does not infinite loop but for me it does not
crash, it runs perfectly. Here is my output:
$ g++ HW1.cpp
$ ./a.out
23
Mary had a little lamb.
ary had a little lamb.
ry had a little lamb.
y had a little lamb.
had a little lamb.
had a little lamb.
ad a little lamb.
d a little lamb.
a little lamb.
a little lamb.
little lamb.
little lamb.
ittle lamb.
ttle lamb.
tle lamb.
le lamb.
e lamb.
lamb.
lamb.
amb.
mb.
b.
.
15
Thar she blows!
har she blows!
ar she blows!
r she blows!
she blows!
she blows!
he blows!
e blows!
blows!
blows!
lows!
ows!
ws!
s!
!
Is there any reason that anyone can think of why this would be? I showed my
professor and he is the one who suggested I submit a bug. It does this under
linux, but in windows using devC++(using a windows port of g++) it breaks as
its supposed to.
--
bachmann dot matt at gmail dot com changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32786
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/32786] Incorrect code compiles and runs well
2007-07-17 2:23 [Bug c++/32786] New: Incorrect code compiles and runs well bachmann dot matt at gmail dot com
2007-07-17 3:17 ` [Bug c++/32786] " pinskia at gcc dot gnu dot org
2007-07-17 3:39 ` bachmann dot matt at gmail dot com
@ 2007-07-17 3:58 ` pinskia at gcc dot gnu dot org
2007-07-17 4:04 ` bachmann dot matt at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-07-17 3:58 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from pinskia at gcc dot gnu dot org 2007-07-17 03:58 -------
No, it is crashing. Anyways this is just undefined behavior so any behavior
here is ok :).
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32786
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/32786] Incorrect code compiles and runs well
2007-07-17 2:23 [Bug c++/32786] New: Incorrect code compiles and runs well bachmann dot matt at gmail dot com
` (2 preceding siblings ...)
2007-07-17 3:58 ` pinskia at gcc dot gnu dot org
@ 2007-07-17 4:04 ` bachmann dot matt at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: bachmann dot matt at gmail dot com @ 2007-07-17 4:04 UTC (permalink / raw)
To: gcc-bugs
------- Comment #4 from bachmann dot matt at gmail dot com 2007-07-17 04:04 -------
alright then. ::shrugs::
thanks
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32786
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2007-07-17 4:04 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-07-17 2:23 [Bug c++/32786] New: Incorrect code compiles and runs well bachmann dot matt at gmail dot com
2007-07-17 3:17 ` [Bug c++/32786] " pinskia at gcc dot gnu dot org
2007-07-17 3:39 ` bachmann dot matt at gmail dot com
2007-07-17 3:58 ` pinskia at gcc dot gnu dot org
2007-07-17 4:04 ` bachmann dot matt at gmail 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).