From: Henning Schmiedehausen <hps@intermeta.de>
To: "Randy.Dunlap" <rddunlap@osdl.org>
Cc: linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Re: sscanf("-1", "%d", &i) fails, returns 0
Date: 11 Nov 2002 10:27:53 +0100 [thread overview]
Message-ID: <1037006873.2011.12.camel@forge> (raw)
In-Reply-To: <Pine.LNX.4.33L2.0211101854350.22017-100000@dragon.pdx.osdl.net>
Hi,
On Mon, 2002-11-11 at 04:05, Randy.Dunlap wrote:
> On Sun, 10 Nov 2002, Henning P. Schmiedehausen wrote:
>
> | "Randy.Dunlap" <rddunlap@osdl.org> writes:
> |
> | >+ digit = *str;
> | >+ if (is_sign && digit == '-')
> | >+ digit = *(str + 1);
> |
> | If signed is not allowed and you get a "-", you're in an error case
> | again...
>
> Yes, and a 0 value is returned.
> IOW, asking for an unsigned number (in the format string)
> and getting "-123" does return 0.
>
> What should it do?
I would model this after user space. (Which does strange things:
--- cut ---
#include <stdio.h>
main()
{
char *scan = "-100";
unsigned int foo;
int bar;
int res = sscanf(scan, "%ud", &foo);
printf("%s = %ud = %d\n", scan, foo, res);
res = sscanf(scan, "%ud", &bar);
printf("%s = %d = %d\n", scan, bar, res);
}
--- cut ---
% gcc -o xxx xxx.c
./xxx
-100 = 4294967196d = 1
-100 = -100 = 1
Hm, so I guess, yes, a warning message would be nice IMHO. Returning an
error code would IMHO moot, because noone is checking these codes
anyway.
Regards
Henning
> This function can't return -EINPUTERROR or -EILSEQ.
> (since it's after feature-freeze :)
> And the original problem was that a leading '-' sign on a
> signed number (!) caused a return of 0. At least that is fixed.
>
> So now the problem (?) is that a '-' sign on an unsigned number
> returns 0. We can always add a big printk() there that
> something is foul. Other ideas?
--
Dipl.-Inf. (Univ.) Henning P. Schmiedehausen -- Geschaeftsfuehrer
INTERMETA - Gesellschaft fuer Mehrwertdienste mbH hps@intermeta.de
Am Schwabachgrund 22 Fon.: 09131 / 50654-0 info@intermeta.de
D-91054 Buckenhof Fax.: 09131 / 50654-20
next prev parent reply other threads:[~2002-11-11 9:21 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2002-11-08 13:32 sscanf("-1", "%d", &i) fails, returns 0 Douglas Gilbert
2002-11-08 19:22 ` [PATCH] " Randy.Dunlap
2002-11-08 19:41 ` Richard B. Johnson
2002-11-08 19:59 ` Randy.Dunlap
2002-11-08 20:19 ` Linus Torvalds
2002-11-08 22:09 ` Randy.Dunlap
2002-11-10 13:41 ` Henning P. Schmiedehausen
2002-11-11 3:05 ` Randy.Dunlap
2002-11-11 4:19 ` Randy.Dunlap
2002-11-11 9:27 ` Henning Schmiedehausen [this message]
2002-11-11 14:38 ` Andreas Schwab
2002-11-08 20:23 ` Richard B. Johnson
-- strict thread matches above, loose matches on Subject: below --
2002-11-11 14:54 Ray Lee
2002-11-11 19:09 ` Randy.Dunlap
2002-11-11 20:08 ` Andreas Schwab
2002-11-11 20:25 ` Ray Lee
2002-11-13 7:06 ` Randy.Dunlap
2002-11-14 17:34 ` Ray Lee
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=1037006873.2011.12.camel@forge \
--to=hps@intermeta.de \
--cc=linux-kernel@vger.kernel.org \
--cc=rddunlap@osdl.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