This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/55148] New: wrong compilation of chars: overlapped memory areas


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!


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]