* [PATCH] Fix valgrind reported issue during char constant lexing (PR c++/69628)
@ 2016-02-03 20:05 Jakub Jelinek
2016-02-05 19:20 ` Bernd Schmidt
0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2016-02-03 20:05 UTC (permalink / raw)
To: gcc-patches
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.
--- 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
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH] Fix valgrind reported issue during char constant lexing (PR c++/69628)
2016-02-03 20:05 [PATCH] Fix valgrind reported issue during char constant lexing (PR c++/69628) Jakub Jelinek
@ 2016-02-05 19:20 ` Bernd Schmidt
0 siblings, 0 replies; 2+ messages in thread
From: Bernd Schmidt @ 2016-02-05 19:20 UTC (permalink / raw)
To: Jakub Jelinek, gcc-patches
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-02-05 19:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-02-03 20:05 [PATCH] Fix valgrind reported issue during char constant lexing (PR c++/69628) Jakub Jelinek
2016-02-05 19:20 ` Bernd Schmidt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).