From: echristo Date: Tue, 15 Feb 2005 23:18:04 +0000 (+0000) Subject: 2005-02-15 Eric Christopher X-Git-Url: http://git.sourceforge.jp/view?p=pf3gnuchains%2Fgcc-fork.git;a=commitdiff_plain;h=9936e07d9194ed249cb7581e2b3b612e98844cde;hp=a606f1d66ed166d39f547f06331f7e027abfc504 2005-02-15 Eric Christopher PR preprocessor/19077 * macro.c (cpp_macro_definition): Move handling of whitespace to PREV_WHITE conditional. Remove overloading of len variable. 2005-02-15 Eric Christopher * gcc.dg/cpp/20050215-1.c: New file. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@95080 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index fc56108b49e..34b9f12ddcd 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2005-02-15 Eric Christopher + + * gcc.dg/cpp/20050215-1.c: New file. + 2005-02-15 James A. Morrison PR tree-optimization/15785 diff --git a/gcc/testsuite/gcc.dg/cpp/20050215-1.c b/gcc/testsuite/gcc.dg/cpp/20050215-1.c new file mode 100644 index 00000000000..e5aaf220e3e --- /dev/null +++ b/gcc/testsuite/gcc.dg/cpp/20050215-1.c @@ -0,0 +1,10 @@ +/* Testcase for memory corruption bug in macro processing. + See PR preprocessor/19077 for details. */ + +/* { dg-do compile } */ +/* { dg-options "-g3" } */ +#define FOO(a,b,c,d,e) a b c d e \ +" " \ +" " \ +" " +int i; diff --git a/libcpp/ChangeLog b/libcpp/ChangeLog index 26e65045380..5c58eb7ceb8 100644 --- a/libcpp/ChangeLog +++ b/libcpp/ChangeLog @@ -1,3 +1,10 @@ +2005-02-15 Eric Christopher + + PR preprocessor/19077 + * macro.c (cpp_macro_definition): Move handling of whitespace + to PREV_WHITE conditional. Remove overloading of len + variable. + 2005-02-14 Kazu Hirata * directives.c, files.c, init.c, internal.h, macro.c, pch.c, diff --git a/libcpp/macro.c b/libcpp/macro.c index 7ad13963537..5e596699e01 100644 --- a/libcpp/macro.c +++ b/libcpp/macro.c @@ -1666,6 +1666,7 @@ cpp_macro_definition (cpp_reader *pfile, const cpp_hashnode *node) len += NODE_LEN (macro->params[i]) + 1; /* "," */ } + /* This should match below where we fill in the buffer. */ if (CPP_OPTION (pfile, traditional)) len += _cpp_replacement_text_len (macro); else @@ -1677,11 +1678,14 @@ cpp_macro_definition (cpp_reader *pfile, const cpp_hashnode *node) if (token->type == CPP_MACRO_ARG) len += NODE_LEN (macro->params[token->val.arg_no - 1]); else - len += cpp_token_len (token) + 1; /* Includes room for ' '. */ + len += cpp_token_len (token); + if (token->flags & STRINGIFY_ARG) len++; /* "#" */ if (token->flags & PASTE_LEFT) len += 3; /* " ##" */ + if (token->flags & PREV_WHITE) + len++; /* " " */ } } @@ -1741,10 +1745,10 @@ cpp_macro_definition (cpp_reader *pfile, const cpp_hashnode *node) if (token->type == CPP_MACRO_ARG) { - len = NODE_LEN (macro->params[token->val.arg_no - 1]); memcpy (buffer, - NODE_NAME (macro->params[token->val.arg_no - 1]), len); - buffer += len; + NODE_NAME (macro->params[token->val.arg_no - 1]), + NODE_LEN (macro->params[token->val.arg_no - 1])); + buffer += NODE_LEN (macro->params[token->val.arg_no - 1]); } else buffer = cpp_spell_token (pfile, token, buffer);