From: "Richard B. Johnson" <root@chaos.analogic.com>
To: Riley Williams <Riley@Williams.Name>
Cc: Kevin Corry <kevcorry@us.ibm.com>,
viro@parcelfarce.linux.theplanet.co.uk,
Bodo Rzany <bodo@rzany.de>,
Linux kernel <linux-kernel@vger.kernel.org>
Subject: RE: is there small mistake in lib/vsprintf.c of kernel 2.4.20 ?
Date: Fri, 2 May 2003 13:15:35 -0400 (EDT) [thread overview]
Message-ID: <Pine.LNX.4.53.0305021305250.9707@chaos> (raw)
In-Reply-To: <BKEGKPICNAKILKJKMHCAKEBLCKAA.Riley@Williams.Name>
On Fri, 2 May 2003, Riley Williams wrote:
> Hi Richard.
>
> >>>>> IOW, %d _does_ mean base=10. base=0 is %i. That goes
> >>>>> both for kernel and userland implementations of scanf
> >>>>> family (and for any standard-compliant implementation,
> >>>>> for that matter).
>
> > What!??????
> >
> > The base, in the kernel code is the number that you divide by
> > to return the remainder for numerical conversions! the base
> > is 8 or octal, 10 for decimal, 16 for hexadecimal, and up to
> > 36 for some other strange unused thing (all 26 letters of the
> > alphabet).
>
> If you read the definition of the scanf() family of functions, you
> will note that a base of 0 is used to indicate that the standard C
> prefixes should be honoured, such that a number beginning with 0x
> is read as hexadecimal, a number beginning with 0 is read as octal
> and any other number is read as decimal. As a result, the value of
> 0 for base IS valid but is special cased.
>
> Think of it like the code that reads from a file. When the end of
> the file is reached, the "character" EOF (code -1) is returned.
> Such is not a valid character in the normal sense of the word, but
> a special case that the function can produce.
>
> > If your conversion chances the base to 0, you divide by 0 (not
> > good) and don't get a remainder. Actually procedure number()
> > protects against a base less than 2 or greater than 36 so you
> > just prevent conversion altogether.
>
> If your conversion puts the base as 0, the code says "ah, we don't
> know what base to use, so we look at the first few digits to decide"
> and follows the above rules. Not a problem.
>
> Best wishes from Riley.
> ---
The base, shown in the definition in scanf() does not have any
correlation to the names of the internal variables used. The
current code, correctly uses the base of 10 when %d, %u, %l, and
all the other decimal variants are encountered, and correctly
uses base octal when %o is encountered, and correctly uses
base 16 when %x or its variations are encountered. The only
known problem is not a problem with base, but a problem with
scanning the string because the standard allows 0x to preceed
a hexadecimal number.
Kevin Corry <kevcorry@us.ibm.com>, submitted a patch which breaks
already working code in an aparent attempt to fix the leading
"0x" problem.
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.
next parent reply other threads:[~2003-05-02 17:01 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <BKEGKPICNAKILKJKMHCAKEBLCKAA.Riley@Williams.Name>
2003-05-02 17:15 ` Richard B. Johnson [this message]
2003-05-02 18:23 ` Kevin Corry
2003-05-02 9:06 Bodo Rzany
2003-05-02 9:08 ` viro
2003-05-02 9:42 ` Bodo Rzany
2003-05-02 9:50 ` viro
2003-05-02 15:03 ` Kevin Corry
2003-05-02 15:27 ` Richard B. Johnson
2003-05-02 16:52 ` Jonathan Lundell
2003-05-02 17:20 ` Richard B. Johnson
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.0305021305250.9707@chaos \
--to=root@chaos.analogic.com \
--cc=Riley@Williams.Name \
--cc=bodo@rzany.de \
--cc=kevcorry@us.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=viro@parcelfarce.linux.theplanet.co.uk \
/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®