From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753566AbbEHS3U (ORCPT ); Fri, 8 May 2015 14:29:20 -0400 Received: from mail-wi0-f182.google.com ([209.85.212.182]:35887 "EHLO mail-wi0-f182.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752755AbbEHS3P (ORCPT ); Fri, 8 May 2015 14:29:15 -0400 Date: Fri, 8 May 2015 21:29:11 +0300 From: Alexey Dobriyan To: akpm@linux-foundation.org Cc: linux-kernel@vger.kernel.org, linux@rasmusvillemoes.dk Subject: [PATCH 01/12] kstrto*: accept "-0" for signed conversion Message-ID: <20150508182911.GA9044@p183.telecom.by> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.23 (2014-03-12) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org strtol(3) et al accept "-0", so should we. Signed-off-by: Alexey Dobriyan --- lib/kstrtox.c | 2 +- lib/test-kstrtox.c | 6 +----- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/kstrtox.c b/lib/kstrtox.c index ec8da78..94be244 100644 --- a/lib/kstrtox.c +++ b/lib/kstrtox.c @@ -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 { diff --git a/lib/test-kstrtox.c b/lib/test-kstrtox.c index 4137bca..f355f67 100644 --- a/lib/test-kstrtox.c +++ b/lib/test-kstrtox.c @@ -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},