[PATCH 4/4] lib/vsprintf: add missing (u8) cast in format_decode() lookup

From: Josh Law

Date: Tue Mar 24 2026 - 18:55:01 EST


The first lookup into the format_state table correctly casts to (u8)
at line 2778, but the second lookup after consuming a length qualifier
does not. On signed-char platforms, a byte >= 0x80 sign-extends to a
negative index, reading before the array.

Add the same (u8) cast for consistency.

Signed-off-by: Josh Law <objecting@xxxxxxxxxxxxx>
---
lib/vsprintf.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 2758096b6f53..3108823e8c22 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -2783,7 +2783,7 @@ struct fmt format_decode(struct fmt fmt, struct printf_spec *spec)
fmt.str++;
}
fmt.str++;
- p = lookup_state + *fmt.str;
+ p = lookup_state + (u8)*fmt.str;
}
if (p->state) {
if (p->base)
--
2.34.1