From: "Jan Beulich" <JBeulich@suse.com>
To: "Namit Gupta" <namit2010@gmail.com>
Cc: "George Spelvin" <linux@horizon.com>,
"Andrei Emeltchenko" <andrei.emeltchenko@intel.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
"open list" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH] Lib:The patch include fix for "-" during string to long conversion
Date: Mon, 05 Nov 2012 08:26:43 +0000 [thread overview]
Message-ID: <5097865302000078000A6487@nat28.tlf.novell.com> (raw)
In-Reply-To: <CAKMXDJXssksA0dtyfe5dTt0RerZzTWOORWCZCZdJF7WAp56=Ng@mail.gmail.com>
>>> On 04.11.12 at 14:26, Namit Gupta <namit2010@gmail.com> wrote:
> API simple_strtol() and simple_strtoul() are giving incorrect result for
> string "-".
> These API's consider "-" as a '-' (negative integer) and return incorrect
> string pointer.
> The API returns pointer next to '-' character. However it should return
> starting pointer of the string.
Where is that behavior specified? If we take the C standard as
reference, it is not being made explicit whether, for "base" other
than zero, the sequence of letters and digits has to be non-empty.
If we take this as implied, then your patch should not only handle
"-" alone, but also cases where "-" is followed by other than a
letter or digit, or an out of range one.
Jan
> Below I have included possible solution for that issue.
> Please review.
>
>
> From eea8b5fd7e5bb7b206a41f5eec934152a77a9431 Mon Sep 17 00:00:00 2001
> From: Namit Gupta <namit2010@gmail.com>
> Date: Sun, 4 Nov 2012 23:36:23 +0530
> Subject: [PATCH 1/1] Lib:The patch include fix for "-" during string to
> long conversion
>
> API simple_strtol and simple_strtoll give wrong result for string "-",
> The API consider "-" as a -ve number which and give incorrect result
> for "-" string.
>
> Signed-off-by: Namit Gupta <namit2010@gmail.com>
> ---
> lib/vsprintf.c | 20 ++++++++++++++++----
> 1 files changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/lib/vsprintf.c b/lib/vsprintf.c
> index 39c99fe..cde449d 100644
> --- a/lib/vsprintf.c
> +++ b/lib/vsprintf.c
> @@ -76,8 +76,14 @@ EXPORT_SYMBOL(simple_strtoul);
> */
> long simple_strtol(const char *cp, char **endp, unsigned int base)
> {
> - if (*cp == '-')
> - return -simple_strtoul(cp + 1, endp, base);
> + if (*cp == '-') {
> + if (*(cp+1))
> + return -simple_strtoul(cp + 1, endp, base);
> + else if (*endp) { /* The string contains only "-"*/
> + *endp = (char *)cp;
> + return 0;
> + }
> + }
>
> return simple_strtoul(cp, endp, base);
> }
> @@ -91,8 +97,14 @@ EXPORT_SYMBOL(simple_strtol);
> */
> long long simple_strtoll(const char *cp, char **endp, unsigned int base)
> {
> - if (*cp == '-')
> - return -simple_strtoull(cp + 1, endp, base);
> + if (*cp == '-') {
> + if (*(cp+1))
> + return -simple_strtoull(cp + 1, endp, base);
> + else if (*endp) { /* The string contains only "-"*/
> + *endp = (char *)cp;
> + return 0;
> + }
> + }
>
> return simple_strtoull(cp, endp, base);
> }
> --
> 1.7.1
>
>
> Regards,
> Namit
next prev parent reply other threads:[~2012-11-05 8:26 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <CAKMXDJXssksA0dtyfe5dTt0RerZzTWOORWCZCZdJF7WAp56=Ng@mail.gmail.com>
2012-11-04 22:25 ` George Spelvin
2012-11-05 8:26 ` Jan Beulich [this message]
[not found] <CAKMXDJXktVEK1XFa0P+O_EHkt6Uvb9f8UcdasaNyCLPZ+G-GcQ@mail.gmail.com>
2012-11-18 14:04 ` George Spelvin
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=5097865302000078000A6487@nat28.tlf.novell.com \
--to=jbeulich@suse.com \
--cc=akpm@linux-foundation.org \
--cc=andrei.emeltchenko@intel.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@horizon.com \
--cc=namit2010@gmail.com \
/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®