Re: [PATCH] ext4: improve str2hashbuf by processing 4-byte chunks

From: Theodore Tso

Date: Thu Nov 20 2025 - 10:58:27 EST


On Sun, Nov 16, 2025 at 07:35:13PM +0000, David Laight wrote:
>
> The (int) casts are unnecessary (throughout), 'char' is always promoted to
> 'signed int' before any arithmetic.

nit: in this case the casts aren't necessary, but your comment is not
correct in general, so I just wanted to make sure it's corrected in
case someone later looks at the mail archive.

"char" is not always signed. It can be signed or unsigned; the C
specification allows either. In this particular case, scp is a
"signed char", not "char".

Secondly, it's not that a promotion happens before "any" arithmetic.
If we add two 8-bit values together, promotion doesn't happen. In
this case, we are adding a signed char to an int, so the promotion
will happen.

Cheers,

- Ted