aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorMartin Sebor <msebor@redhat.com>2018-09-14 03:34:19 +0000
committerJeff Law <law@gcc.gnu.org>2018-09-13 21:34:19 -0600
commit6ab24ea809555eeb869fe49595f22ed9c8737cc4 (patch)
treea6a98bb3c25e71934a2ae133c6e5116dcb9349b9 /gcc/fold-const.c
parentd01b568a78351beb6b693b613e6b48bcb2475eae (diff)
downloadgcc-6ab24ea809555eeb869fe49595f22ed9c8737cc4.zip
gcc-6ab24ea809555eeb869fe49595f22ed9c8737cc4.tar.gz
gcc-6ab24ea809555eeb869fe49595f22ed9c8737cc4.tar.bz2
builtins.h (c_srlen): Add argument.
* builtins.h (c_srlen): Add argument. * builtins.c (warn_string_no_nul): New function. (c_strlen): Add argument and use it. Update recursive calls. Pass DECL argument to string_constant to get info on non terminated strings. Update *NONSTR as needed. (fold_builtin_strlen): Add argument to calls to c_strlen. Warn for unterminated arrays. (warn_string_no_null): Add prototype. * expr.c (string_constant): Update arguments. Update recursive calls appropriately. Detect missing NUL terminator and outermost declaration its missing in. Improve checks for arrays with nonzero lower bound or elements that are not a single byte. Simplify offset computation. Simplify checks for non-NUL terminated strings. * gimple-fold.c (get_range_strlen): Add argument to c_strlen call. * gimple-ssa-sprintf.c (get_string_length): Remove unnecessary code. * gcc.dg/warn-strlen-no-nul.c: New test. Co-Authored-By: Bernd Edlinger <bernd.edlinger@hotmail.de> Co-Authored-By: Jeff Law <law@redhat.com> From-SVN: r264302
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index e18ee28..6b4b6a4 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -14595,6 +14595,10 @@ c_getstr (tree src, unsigned HOST_WIDE_INT *strlen /* = NULL */)
unsigned HOST_WIDE_INT string_length = TREE_STRING_LENGTH (src);
unsigned HOST_WIDE_INT string_size = tree_to_uhwi (mem_size);
+ /* Ideally this would turn into a gcc_checking_assert over time. */
+ if (string_length > string_size)
+ string_length = string_size;
+
const char *string = TREE_STRING_POINTER (src);
/* Ideally this would turn into a gcc_checking_assert over time. */