aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexey Dobriyan <adobriyan@gmail.com>2015-09-09 18:36:17 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2015-09-10 16:29:01 -0400
commit2d2e4715a65ca7e81b292d01ae009a03ccedb9b5 (patch)
tree540fd65bc0d6d914dd8c5074d63074d3dc8d4f23
parent3cdea4d71439fb5676b7334a333dab0f7b1bd2e9 (diff)
kstrto*: accept "-0" for signed conversion
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>
-rw-r--r--lib/kstrtox.c2
-rw-r--r--lib/test-kstrtox.c6
2 files changed, 2 insertions, 6 deletions
diff --git a/lib/kstrtox.c b/lib/kstrtox.c
index ec8da78df9be..94be244e8441 100644
--- a/lib/kstrtox.c
+++ b/lib/kstrtox.c
@@ -152,7 +152,7 @@ int kstrtoll(const char *s, unsigned int base, long long *res)
152 rv = _kstrtoull(s + 1, base, &tmp); 152 rv = _kstrtoull(s + 1, base, &tmp);
153 if (rv < 0) 153 if (rv < 0)
154 return rv; 154 return rv;
155 if ((long long)(-tmp) >= 0) 155 if ((long long)-tmp > 0)
156 return -ERANGE; 156 return -ERANGE;
157 *res = -tmp; 157 *res = -tmp;
158 } else { 158 } else {
diff --git a/lib/test-kstrtox.c b/lib/test-kstrtox.c
index 4137bca5f8e8..f355f67169b6 100644
--- a/lib/test-kstrtox.c
+++ b/lib/test-kstrtox.c
@@ -260,6 +260,7 @@ static void __init test_kstrtoll_ok(void)
260 {"4294967297", 10, 4294967297LL}, 260 {"4294967297", 10, 4294967297LL},
261 {"9223372036854775807", 10, 9223372036854775807LL}, 261 {"9223372036854775807", 10, 9223372036854775807LL},
262 262
263 {"-0", 10, 0LL},
263 {"-1", 10, -1LL}, 264 {"-1", 10, -1LL},
264 {"-2", 10, -2LL}, 265 {"-2", 10, -2LL},
265 {"-9223372036854775808", 10, LLONG_MIN}, 266 {"-9223372036854775808", 10, LLONG_MIN},
@@ -277,11 +278,6 @@ static void __init test_kstrtoll_fail(void)
277 {"-9223372036854775809", 10}, 278 {"-9223372036854775809", 10},
278 {"-18446744073709551614", 10}, 279 {"-18446744073709551614", 10},
279 {"-18446744073709551615", 10}, 280 {"-18446744073709551615", 10},
280 /* negative zero isn't an integer in Linux */
281 {"-0", 0},
282 {"-0", 8},
283 {"-0", 10},
284 {"-0", 16},
285 /* sign is first character if any */ 281 /* sign is first character if any */
286 {"-+1", 0}, 282 {"-+1", 0},
287 {"-+1", 8}, 283 {"-+1", 8},