From: David Malcolm Date: Thu, 19 May 2016 18:10:30 +0000 (+0000) Subject: PR c++/71184: Fix NULL dereference in cp_parser_operator X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=5e9a538594761b93843b4285c06bcd871fa0335f;p=gcc.git PR c++/71184: Fix NULL dereference in cp_parser_operator The source-range handling for the array form of operator new/delete erroneously assumed that the "]" was present, leading to a dereference of NULL when it's absent. Fix it thusly. gcc/cp/ChangeLog: PR c++/71184 * parser.c (cp_parser_operator): For array new/delete, check that cp_parser_require returned a non-NULL token before dereferencing it. gcc/testsuite/ChangeLog: PR c++/71184 * g++.dg/pr71184.C: New test case. From-SVN: r236483 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 66c04a6f359..70dbcb3e715 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,10 @@ +2016-05-19 David Malcolm + + PR c++/71184 + * parser.c (cp_parser_operator): For array new/delete, check that + cp_parser_require returned a non-NULL token before dereferencing + it. + 2016-05-19 Bernd Edlinger * decl.c (finish_enum_value_list): Use the specified mode. diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 3abba12fd3e..076e7f36847 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -13791,8 +13791,9 @@ cp_parser_operator (cp_parser* parser) /* Consume the `[' token. */ cp_lexer_consume_token (parser->lexer); /* Look for the `]' token. */ - end_loc = cp_parser_require (parser, CPP_CLOSE_SQUARE, - RT_CLOSE_SQUARE)->location; + if (cp_token *close_token + = cp_parser_require (parser, CPP_CLOSE_SQUARE, RT_CLOSE_SQUARE)) + end_loc = close_token->location; id = ansi_opname (op == NEW_EXPR ? VEC_NEW_EXPR : VEC_DELETE_EXPR); } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index f543d183219..1630598fe31 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-05-19 David Malcolm + + PR c++/71184 + * g++.dg/pr71184.C: New test case. + 2016-05-19 Kelvin Nilsen * gcc.target/powerpc/darn-0.c: New test. diff --git a/gcc/testsuite/g++.dg/pr71184.C b/gcc/testsuite/g++.dg/pr71184.C new file mode 100644 index 00000000000..452303e47a1 --- /dev/null +++ b/gcc/testsuite/g++.dg/pr71184.C @@ -0,0 +1 @@ +operator new[ // { dg-error "expected type-specifier before 'new'" }