Skip to content

Commit 2d2e471

Browse files
Alexey Dobriyantorvalds
authored andcommitted
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>
1 parent 3cdea4d commit 2d2e471

File tree

2 files changed

+2
-6
lines changed

2 files changed

+2
-6
lines changed

lib/kstrtox.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ int kstrtoll(const char *s, unsigned int base, long long *res)
152152
rv = _kstrtoull(s + 1, base, &tmp);
153153
if (rv < 0)
154154
return rv;
155-
if ((long long)(-tmp) >= 0)
155+
if ((long long)-tmp > 0)
156156
return -ERANGE;
157157
*res = -tmp;
158158
} else {

lib/test-kstrtox.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,7 @@ static void __init test_kstrtoll_ok(void)
260260
{"4294967297", 10, 4294967297LL},
261261
{"9223372036854775807", 10, 9223372036854775807LL},
262262

263+
{"-0", 10, 0LL},
263264
{"-1", 10, -1LL},
264265
{"-2", 10, -2LL},
265266
{"-9223372036854775808", 10, LLONG_MIN},
@@ -277,11 +278,6 @@ static void __init test_kstrtoll_fail(void)
277278
{"-9223372036854775809", 10},
278279
{"-18446744073709551614", 10},
279280
{"-18446744073709551615", 10},
280-
/* negative zero isn't an integer in Linux */
281-
{"-0", 0},
282-
{"-0", 8},
283-
{"-0", 10},
284-
{"-0", 16},
285281
/* sign is first character if any */
286282
{"-+1", 0},
287283
{"-+1", 8},

0 commit comments

Comments
 (0)