PR c++/71184: Fix NULL dereference in cp_parser_operator
authorDavid Malcolm <dmalcolm@redhat.com>
Thu, 19 May 2016 18:10:30 +0000 (18:10 +0000)
committerDavid Malcolm <dmalcolm@gcc.gnu.org>
Thu, 19 May 2016 18:10:30 +0000 (18:10 +0000)
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

gcc/cp/ChangeLog
gcc/cp/parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/pr71184.C [new file with mode: 0644]

index 66c04a6f359c9971bac4d411b1823a754c4c9d1a..70dbcb3e7159d0f73f326ff758ba8afce77d796a 100644 (file)
@@ -1,3 +1,10 @@
+2016-05-19  David Malcolm  <dmalcolm@redhat.com>
+
+       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  <bernd.edlinger@hotmail.de>
 
        * decl.c (finish_enum_value_list): Use the specified mode.
index 3abba12fd3ee1e379bc6fe41152c03fa010473a3..076e7f368476e6fd9a3d099d0080f641acb3df7f 100644 (file)
@@ -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);
          }
index f543d183219c903efe8ad37c8a41ac2a26b6ae32..1630598fe3124b14a510c180c226a8016cc81780 100644 (file)
@@ -1,3 +1,8 @@
+2016-05-19  David Malcolm  <dmalcolm@redhat.com>
+
+       PR c++/71184
+       * g++.dg/pr71184.C: New test case.
+
 2016-05-19  Kelvin Nilsen  <kelvin@gcc.gnu.org>
 
        * 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 (file)
index 0000000..452303e
--- /dev/null
@@ -0,0 +1 @@
+operator new[ // { dg-error "expected type-specifier before 'new'" }