aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorBernd Edlinger <bernd.edlinger@hotmail.de>2018-09-13 22:00:56 +0000
committerJeff Law <law@gcc.gnu.org>2018-09-13 16:00:56 -0600
commit84b5706abb8f5dff634e588071ab4fef080cd05e (patch)
treefbbd399a14105566dbb3baa5ec09d61c6383055e /gcc
parent5ec9f8cff333bbe9ef6b3767bfcc334961927a03 (diff)
downloadgcc-84b5706abb8f5dff634e588071ab4fef080cd05e.zip
gcc-84b5706abb8f5dff634e588071ab4fef080cd05e.tar.gz
gcc-84b5706abb8f5dff634e588071ab4fef080cd05e.tar.bz2
* fold-const.c (c_getstr): Clamp STRING_LENGTH to STRING_SIZE.
From-SVN: r264293
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog2
-rw-r--r--gcc/fold-const.c4
2 files changed, 6 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 7dfcd97..dfa39f0 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,7 @@
2018-09-13 Bernd Edlinger <bernd.edlinger@hotmail.de>
+ * fold-const.c (c_getstr): Clamp STRING_LENGTH to STRING_SIZE.
+
* varasm.c (compare_constant): Compare type size of STRING_CSTs.
(get_constant_size): Don't make STRING_CSTs larger than they are.
(check_string_literal): New check function for STRING_CSTs.
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 71c18eb..9fc7fc5 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -14611,6 +14611,10 @@ c_getstr (tree src, unsigned HOST_WIDE_INT *strlen /* = NULL */,
const char *string = TREE_STRING_POINTER (src);
+ /* Ideally this would turn into a gcc_checking_assert over time. */
+ if (string_length > string_size)
+ string_length = string_size;
+
if (string_length == 0
|| offset >= string_size)
return NULL;