Re: why does sscanf() does not interpret number length attributes?

From: Richard B. Johnson (
Date: Wed Jul 02 2003 - 15:55:44 EST

On Wed, 2 Jul 2003, Kay Sievers wrote:

> I needed a conversion from hex-string to integer and found
> this mail from Linus suggesting sscanf:
> but sscanf in linux-2.5/lib/vsprintf.c interpretes length attributes
> only when the type is a string. It uses simple_strtoul() and it will
> read the buffer until it finds a non-(hex)digit.
> int i;
> char str[] ="34AFFE45XYZ";
> sscanf(str, "%1x", &i);
> i will be '0x34AFFE45' instead of the expected '3'.
> Is this behaviour intended or is just nobody caring about?

The in-kernel vsprintf() is very primative, used for very simple
things. Note that it doesn't even have "%f". You should just
do something like:

        i = (int) *str + '0';

      ... if you need to read part of a number.

You don't really wany to increase the size of the permanent
in-kernel stuff if you can help. You add any increased functionality
to your modules so it is used only when needed.

Dick Johnson
Penguin : Linux version 2.4.20 on an i686 machine (797.90 BogoMips).
Why is the government concerned about the lunatic fringe? Think about it.

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to
More majordomo info at
Please read the FAQ at

This archive was generated by hypermail 2b29 : Mon Jul 07 2003 - 22:00:17 EST