sscanf %02x and "0x" behaviour

Bug #1829980 reported by Zibri Soft
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
glibc (Ubuntu)
New
Undecided
Unassigned

Bug Description

I wrote this routine to convert a hex string to binary:

https://gist.github.com/Zibri/992b38baa520eb478ef7fa15fd950a7a/raw/2ea3634b31d6c90d74dc2a987a3dfe3b57e6fbcc/hex2bin_by_zibri.c

The routine works nicely but I noticed one thing:

sscanf("%02x",&char)

accepts:

1
02
Aa
aA

but it also accepts

0x which it translates to 00

There's no real harm in that, but I think that should be corrected.
In a loop if the input string (check my routine) is
"0x 0x 12 34 0x 1x 12 34"
The routine translates
00 00 12 34 00

Because for sscanf 0x is not an error but 1x is.
IMHO they should both be treated the same way in "%x"...

Regards,
Zibri

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.