Skip to content

Commit ecdc475

Browse files
committed
vsnprintf: fix the number base for non-numeric formats
Commit 8d4826c ("vsnprintf: collapse the number format state into one single state") changed the format specification decoding to be a bit more straightforward but in the process ended up also resetting the number base to zero for formats that aren't clearly numerical. Now, the number base obviously doesn't matter for something like '%s', so this wasn't all that obvious. But some of our specialized pointer extension formatting (ie, things like "print out IPv6 address") did up depending on the default base-10 setting, and when they then tried to print out numbers in "base zero", things didn't work out so well. Most pointer formatting (including things like the default raw hex value conversion) didn't have this issue, because they used helpers that explicitly set the base. Reported-and-tested-by: kernel test robot <[email protected]> Closes: https://lore.kernel.org/oe-lkp/[email protected] Fixes: 8d4826c ("vsnprintf: collapse the number format state into one single state") Signed-off-by: Linus Torvalds <[email protected]>
1 parent fa47906 commit ecdc475

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

lib/vsprintf.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2682,7 +2682,8 @@ struct fmt format_decode(struct fmt fmt, struct printf_spec *spec)
26822682
p = lookup_state + *fmt.str;
26832683
}
26842684
if (p->state) {
2685-
spec->base = p->base;
2685+
if (p->base)
2686+
spec->base = p->base;
26862687
spec->flags |= p->flags_or_double_size;
26872688
fmt.state = p->state;
26882689
fmt.str++;

0 commit comments

Comments
 (0)