mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Richard B. Johnson" <root@chaos.analogic.com>
To: Kay Sievers <lkml001@vrfy.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: why does sscanf() does not interpret number length attributes?
Date: Wed, 2 Jul 2003 16:55:44 -0400 (EDT)	[thread overview]
Message-ID: <Pine.LNX.4.53.0307021644550.26973@chaos> (raw)
In-Reply-To: <20030702203433.GA14854@vrfy.org>

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:
>
> http://marc.theaimsgroup.com/?l=linux-kernel&m=101414195507893&w=2
>
> 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.

Cheers,
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.


  reply	other threads:[~2003-07-02 20:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-07-02 20:34 Kay Sievers
2003-07-02 20:55 ` Richard B. Johnson [this message]
2003-07-02 22:26   ` Kay Sievers
2003-07-02 23:00 ` Stephen Wille Padnos

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.53.0307021644550.26973@chaos \
    --to=root@chaos.analogic.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lkml001@vrfy.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®