aboutsummaryrefslogtreecommitdiff
path: root/libcpp/charset.c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2019-12-14 23:18:53 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2019-12-14 23:18:53 +0100
commit937a778ea37e129a758c44a3868d3842e5cd62ab (patch)
treeb99aebf59c0866c23732650a346899249db85a1b /libcpp/charset.c
parent8640a704710ef6a3b57b9c43bc3dee1bb5452e3d (diff)
downloadgcc-937a778ea37e129a758c44a3868d3842e5cd62ab.zip
gcc-937a778ea37e129a758c44a3868d3842e5cd62ab.tar.gz
gcc-937a778ea37e129a758c44a3868d3842e5cd62ab.tar.bz2
re PR preprocessor/92919 (invalid memory access in wide_str_to_charconst when running ucn2.C testcase (caught by hwasan))
PR preprocessor/92919 * charset.c (wide_str_to_charconst): If str contains just the NUL terminator, punt quietly. From-SVN: r279399
Diffstat (limited to 'libcpp/charset.c')
-rw-r--r--libcpp/charset.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/libcpp/charset.c b/libcpp/charset.c
index 956d2da..a638a1b 100644
--- a/libcpp/charset.c
+++ b/libcpp/charset.c
@@ -1970,6 +1970,17 @@ wide_str_to_charconst (cpp_reader *pfile, cpp_string str,
size_t off, i;
cppchar_t result = 0, c;
+ if (str.len <= nbwc)
+ {
+ /* Error recovery, if no errors have been diagnosed previously,
+ there should be at least two wide characters. Empty literals
+ are diagnosed earlier and we can get just the zero terminator
+ only if there were errors diagnosed during conversion. */
+ *pchars_seen = 0;
+ *unsignedp = 0;
+ return 0;
+ }
+
/* This is finicky because the string is in the target's byte order,
which may not be our byte order. Only the last character, ignoring
the NUL terminator, is relevant. */