Skip to content

Commit 5b17f53

Browse files
committed
Fix scanf() handling of %x or %o with no prefix
1 parent 2af2019 commit 5b17f53

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

examples/stdlib.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4400,15 +4400,31 @@ static __attribute__((__noinline__)) bool scanf_get_num(
44004400
if (!scanf_get_oct(in, &width, &i, &overflow))
44014401
return false;
44024402
}
4403-
else
4403+
else /* if (flags & SCANF_FLAG_HEX) */
4404+
{
44044405
scanf_unget_char_n(c, in, &width);
4406+
if (!scanf_get_hex(in, &width, &i, &overflow))
4407+
return false;
4408+
}
44054409
}
44064410
else if (flags & SCANF_FLAG_DEC)
44074411
{
44084412
scanf_unget_char_n(c, in, &width);
44094413
if (!scanf_get_dec(in, &width, &i, &overflow))
44104414
return false;
44114415
}
4416+
else if (flags & SCANF_FLAG_OCT)
4417+
{
4418+
scanf_unget_char_n(c, in, &width);
4419+
if (!scanf_get_oct(in, &width, &i, &overflow))
4420+
return false;
4421+
}
4422+
else if (flags & SCANF_FLAG_HEX)
4423+
{
4424+
scanf_unget_char_n(c, in, &width);
4425+
if (!scanf_get_hex(in, &width, &i, &overflow))
4426+
return false;
4427+
}
44124428
else
44134429
{
44144430
scanf_unget_char_n(c, in, &width);

0 commit comments

Comments
 (0)