kstrto*: accept "-0" for signed conversion
authorAlexey Dobriyan <adobriyan@gmail.com>
Wed, 9 Sep 2015 22:36:17 +0000 (15:36 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Thu, 10 Sep 2015 20:29:01 +0000 (13:29 -0700)
strtol(3) et al accept "-0", so should we.

Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Cc: David Howells <dhowells@redhat.com>
Cc: Jan Kara <jack@suse.cz>
Cc: Joel Becker <jlbec@evilplan.org>
Cc: Mark Fasheh <mfasheh@suse.com>
Cc: Theodore Ts'o <tytso@mit.edu>
Cc: Rasmus Villemoes <linux@rasmusvillemoes.dk>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
lib/kstrtox.c
lib/test-kstrtox.c

index ec8da78df9be9f4ea245ff398193bd1d90210573..94be244e844103d0fb6ed20c7bee905ca908fa12 100644 (file)
@@ -152,7 +152,7 @@ int kstrtoll(const char *s, unsigned int base, long long *res)
                rv = _kstrtoull(s + 1, base, &tmp);
                if (rv < 0)
                        return rv;
-               if ((long long)(-tmp) >= 0)
+               if ((long long)-tmp > 0)
                        return -ERANGE;
                *res = -tmp;
        } else {
index 4137bca5f8e8e5008ca88b7fcb801096856eaf0c..f355f67169b6a32fbb7162b46691a45de4291cd2 100644 (file)
@@ -260,6 +260,7 @@ static void __init test_kstrtoll_ok(void)
                {"4294967297",  10,     4294967297LL},
                {"9223372036854775807", 10,     9223372036854775807LL},
 
+               {"-0",  10,     0LL},
                {"-1",  10,     -1LL},
                {"-2",  10,     -2LL},
                {"-9223372036854775808",        10,     LLONG_MIN},
@@ -277,11 +278,6 @@ static void __init test_kstrtoll_fail(void)
                {"-9223372036854775809",        10},
                {"-18446744073709551614",       10},
                {"-18446744073709551615",       10},
-               /* negative zero isn't an integer in Linux */
-               {"-0",  0},
-               {"-0",  8},
-               {"-0",  10},
-               {"-0",  16},
                /* sign is first character if any */
                {"-+1", 0},
                {"-+1", 8},