Hi!

If we report error from cpp_interpret_charconst (or functions it calls),
we leave *pchars_seen and *unsignedp uninitialized, and as the return
value for error (0) is also valid return value for valid programs,
various callers look at the uninitialized variables.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for
trunk?

2016-02-03  Jakub Jelinek  <ja...@redhat.com>

        PR c++/69628
        * charset.c (cpp_interpret_charconst): Clear *PCHARS_SEEN
        and *UNSIGNEDP if bailing out early due to errors.

        * g++.dg/parse/pr69628.C: New test.

--- libcpp/charset.c.jj 2016-01-04 15:14:08.000000000 +0100
+++ libcpp/charset.c    2016-02-03 13:44:05.100120898 +0100
@@ -1620,10 +1620,17 @@ cpp_interpret_charconst (cpp_reader *pfi
   if (token->val.str.len == (size_t) (2 + wide + u8))
     {
       cpp_error (pfile, CPP_DL_ERROR, "empty character constant");
+      *pchars_seen = 0;
+      *unsignedp = 0;
+      return 0;
+    }
+  else if (!cpp_interpret_string (pfile, &token->val.str, 1, &str,
+                                 token->type))
+    {
+      *pchars_seen = 0;
+      *unsignedp = 0;
       return 0;
     }
-  else if (!cpp_interpret_string (pfile, &token->val.str, 1, &str, 
token->type))
-    return 0;
 
   if (wide)
     result = wide_str_to_charconst (pfile, str, pchars_seen, unsignedp,
--- gcc/testsuite/g++.dg/parse/pr69628.C.jj     2016-02-03 13:47:55.300061110 
+0100
+++ gcc/testsuite/g++.dg/parse/pr69628.C        2016-02-03 13:47:32.000000000 
+0100
@@ -0,0 +1,5 @@
+// PR c++/69628
+// { dg-do compile }
+
+0''; // { dg-error "empty character constant" }
+// { dg-error "expected unqualified-id before numeric constant" "" { target 
*-*-* } 4 }

        Jakub

Reply via email to