diff mbox

Fix valgrind reported issue during char constant lexing (PR c++/69628)

Message ID 20160203200528.GE3017@tucnak.redhat.com
State New
Headers show

Commit Message

Jakub Jelinek Feb. 3, 2016, 8:05 p.m. UTC
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  <jakub@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.


	Jakub

Comments

Bernd Schmidt Feb. 5, 2016, 7:20 p.m. UTC | #1
On 02/03/2016 09:05 PM, Jakub Jelinek wrote:
> 2016-02-03  Jakub Jelinek  <jakub@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.

Ok.


Bernd
diff mbox

Patch

--- 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 }