diff options
Diffstat (limited to 'gcc/builtins.c')
-rw-r--r-- | gcc/builtins.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/gcc/builtins.c b/gcc/builtins.c index c9de1e6..58ea747 100644 --- a/gcc/builtins.c +++ b/gcc/builtins.c @@ -567,7 +567,7 @@ string_length (const void *ptr, unsigned eltsize, unsigned maxelts) tree c_strlen (tree src, int only_value, unsigned eltsize) { - gcc_assert (eltsize == 1 || eltsize == 2 || eltsize == 4); + gcc_checking_assert (eltsize == 1 || eltsize == 2 || eltsize == 4); STRIP_NOPS (src); if (TREE_CODE (src) == COND_EXPR && (only_value || !TREE_SIDE_EFFECTS (TREE_OPERAND (src, 0)))) @@ -656,10 +656,10 @@ c_strlen (tree src, int only_value, unsigned eltsize) a null character if we can represent it as a single HOST_WIDE_INT. */ if (byteoff == 0) eltoff = 0; - else if (! tree_fits_shwi_p (byteoff)) + else if (! tree_fits_uhwi_p (byteoff) || tree_to_uhwi (byteoff) % eltsize) eltoff = -1; else - eltoff = tree_to_shwi (byteoff) / eltsize; + eltoff = tree_to_uhwi (byteoff) / eltsize; /* If the offset is known to be out of bounds, warn, and call strlen at runtime. */ @@ -691,6 +691,11 @@ c_strlen (tree src, int only_value, unsigned eltsize) unsigned len = string_length (ptr + eltoff * eltsize, eltsize, strelts - eltoff); + /* Don't know what to return if there was no zero termination. + Ideally this would turn into a gcc_checking_assert over time. */ + if (len > maxelts - eltoff) + return NULL_TREE; + return ssize_int (len); } |