[PATCH] avoid assuming known string length is constant (PR 83896)
Martin Sebor
msebor@gmail.com
Tue Jan 16 22:34:00 GMT 2018
On 01/16/2018 02:26 PM, Jakub Jelinek wrote:
> On Tue, Jan 16, 2018 at 07:37:30PM +0000, Richard Sandiford wrote:
>>> -/* Check if RHS is string_cst possibly wrapped by mem_ref. */
>>> +/* If RHS, either directly or indirectly, refers to a string of constant
>>> + length, return it. Otherwise return a negative value. */
>>> +
>>> static int
>>> get_string_len (tree rhs)
>>> {
>>
>> I think this should be returning HOST_WIDE_INT given the unconstrained
>> tree_to_shwi return. Same type change for rhslen in the caller.
>>
>> (Not my call, but it might be better to have a more specific function name,
>> given that the file already had "get_string_length" before this function
>> was added.)
>
> Yeah, certainly for both.
>
>>> @@ -2789,7 +2791,8 @@ get_string_len (tree rhs)
>>> if (idx > 0)
>>> {
>>> strinfo *si = get_strinfo (idx);
>>> - if (si && si->full_string_p)
>>> + if (si && si->full_string_p
>>> + && TREE_CODE (si->nonzero_chars) == INTEGER_CST)
>>> return tree_to_shwi (si->nonzero_chars);
>>
>> tree_fits_shwi_p?
>
> Surely that instead of TREE_CODE check, but even that will not make sure it
> fits into host int, so yes, it should be HOST_WIDE_INT and the code should
> make sure it is also >= 0.
I made these changes except for the last part: How/when can
the length be negative?
Martin
More information about the Gcc-patches
mailing list