[PATCH 08/11] locale: Fix UB in elem_hash
Adhemerval Zanella Netto
adhemerval.zanella@linaro.org
Thu May 29 15:16:59 GMT 2025
On 20/05/25 10:26, Andreas Schwab wrote:
> On Mai 07 2025, Adhemerval Zanella wrote:
>
>> diff --git a/locale/elem-hash.h b/locale/elem-hash.h
>> index 5d34ec43f3..8052b0fe6d 100644
>> --- a/locale/elem-hash.h
>> +++ b/locale/elem-hash.h
>> @@ -24,7 +24,7 @@ elem_hash (const char *str, int32_t n)
>>
>> while (n-- > 0)
>> {
>> - result <<= 3;
>> + result = (uint32_t)result << 3;
>> result += *str++;
>> }
>
> The only use of elem_hash assigns the value to a uint32_t, so it would
> be better to adjust the return type of the function.
>
It makes sense, I will change it.
More information about the Libc-alpha
mailing list