public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/55148] New: wrong compilation of chars: overlapped memory areas
@ 2012-10-31 12:10 icegood1980 at gmail dot com
2012-10-31 12:17 ` [Bug c++/55148] " redi at gcc dot gnu.org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: icegood1980 at gmail dot com @ 2012-10-31 12:10 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55148
Bug #: 55148
Summary: wrong compilation of chars: overlapped memory areas
Classification: Unclassified
Product: gcc
Version: 4.7.2
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: c++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: icegood1980@gmail.com
if one uses a stringification operation then problems could be obtained on
stack:
brackets.cpp :
#include <iostream>
#include <cstring>
#define GLOBAL_str_intermediate(s) \
({ \
char GLOBAL_str_intermediate_buf[1024]; \
strcpy(GLOBAL_str_intermediate_buf, #s); \
GLOBAL_str_intermediate_buf[strlen(GLOBAL_str_intermediate_buf)-1]='\0'; \
GLOBAL_str_intermediate_buf+1; \
})
#define GLOBAL_str(s) GLOBAL_str_intermediate((s))
#define s_one_arg a,b,c
int main(int argc, const char **argv)
{
char PairPotentialName[70], *p=GLOBAL_str(s_one_arg);
//
std::cerr<<p-PairPotentialName<<std::endl;
std::cerr<<PairPotentialName+1<<std::endl;
return 0;
}
g++ brackets.cpp
./a.out:
1
a,b,c
so PairPotentialName and p are overlapped!
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/55148] wrong compilation of chars: overlapped memory areas
2012-10-31 12:10 [Bug c++/55148] New: wrong compilation of chars: overlapped memory areas icegood1980 at gmail dot com
@ 2012-10-31 12:17 ` redi at gcc dot gnu.org
2012-10-31 12:23 ` redi at gcc dot gnu.org
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2012-10-31 12:17 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55148
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|major |normal
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-10-31 12:16:51 UTC ---
As the docs for the Statement Expressions extension
(http://gcc.gnu.org/onlinedocs/gcc/Statement-Exprs.html) say:
"Any temporaries created within a statement within a statement expression will
be destroyed at the statement's end."
so GLOBAL_str_intermediate_buf[] is no longer valid after p is initialized and
the memory can be reused.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/55148] wrong compilation of chars: overlapped memory areas
2012-10-31 12:10 [Bug c++/55148] New: wrong compilation of chars: overlapped memory areas icegood1980 at gmail dot com
2012-10-31 12:17 ` [Bug c++/55148] " redi at gcc dot gnu.org
@ 2012-10-31 12:23 ` redi at gcc dot gnu.org
2012-10-31 12:40 ` icegood1980 at gmail dot com
2012-10-31 12:43 ` icegood1980 at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: redi at gcc dot gnu.org @ 2012-10-31 12:23 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55148
--- Comment #2 from Jonathan Wakely <redi at gcc dot gnu.org> 2012-10-31 12:22:54 UTC ---
http://gcc.gnu.org/gcc-4.7/changes.html#cxx notes "G++ now properly re-uses
stack space allocated for temporary objects when their lifetime ends, which can
significantly lower stack consumption for some C++ functions. As a result of
this, some code with undefined behavior will now break"
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/55148] wrong compilation of chars: overlapped memory areas
2012-10-31 12:10 [Bug c++/55148] New: wrong compilation of chars: overlapped memory areas icegood1980 at gmail dot com
2012-10-31 12:17 ` [Bug c++/55148] " redi at gcc dot gnu.org
2012-10-31 12:23 ` redi at gcc dot gnu.org
@ 2012-10-31 12:40 ` icegood1980 at gmail dot com
2012-10-31 12:43 ` icegood1980 at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: icegood1980 at gmail dot com @ 2012-10-31 12:40 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55148
icegood1980@gmail.com <icegood1980 at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|normal |major
--- Comment #3 from icegood1980 at gmail dot com <icegood1980 at gmail dot com> 2012-10-31 12:40:16 UTC ---
Clear! it's my fault.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c++/55148] wrong compilation of chars: overlapped memory areas
2012-10-31 12:10 [Bug c++/55148] New: wrong compilation of chars: overlapped memory areas icegood1980 at gmail dot com
` (2 preceding siblings ...)
2012-10-31 12:40 ` icegood1980 at gmail dot com
@ 2012-10-31 12:43 ` icegood1980 at gmail dot com
3 siblings, 0 replies; 5+ messages in thread
From: icegood1980 at gmail dot com @ 2012-10-31 12:43 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55148
icegood1980@gmail.com <icegood1980 at gmail dot com> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
--- Comment #4 from icegood1980 at gmail dot com <icegood1980 at gmail dot com> 2012-10-31 12:43:32 UTC ---
my fault
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2012-10-31 12:43 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-31 12:10 [Bug c++/55148] New: wrong compilation of chars: overlapped memory areas icegood1980 at gmail dot com
2012-10-31 12:17 ` [Bug c++/55148] " redi at gcc dot gnu.org
2012-10-31 12:23 ` redi at gcc dot gnu.org
2012-10-31 12:40 ` icegood1980 at gmail dot com
2012-10-31 12:43 ` icegood1980 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).