From patchwork Fri Feb 20 02:45:07 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 441825 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 8556014017C for ; Fri, 20 Feb 2015 13:45:23 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 622331A0E8F for ; Fri, 20 Feb 2015 13:45:23 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mail-pd0-x241.google.com (mail-pd0-x241.google.com [IPv6:2607:f8b0:400e:c02::241]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id A0E6F1A0E36 for ; Fri, 20 Feb 2015 13:45:20 +1100 (AEDT) Received: by pdbfl12 with SMTP id fl12so2576444pdb.2 for ; Thu, 19 Feb 2015 18:45:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KLJtj4S8ZjQ8FwiauuWAEhgP8G8krJEgnAnuLadv5JU=; b=MkM3LRfiyPNkXHDJMaKUwaYs17pGi9CE7iWMNBzx+ly46UDapJEMTxfvB8ZprSDE/a zcy8vk3h4WOdA+2kT5u9zjbxbGy1m6J/vd16kR81MheMwIKfah9A00SN5lPoi8Gp46C4 TePKkhNpGxpepfdgD0mhWER2Ky0RlljjiWADI= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=KLJtj4S8ZjQ8FwiauuWAEhgP8G8krJEgnAnuLadv5JU=; b=LrDs4aCEWIok45zgL49xXI1IDrMJzVviDrNZzPPh/Td87+4K6j9SV0IoWcov6PU7Fw Ys1D0Iw9kkQDHmwAFdxa6WWir6afAKl0ylmq9KE3mYIdDnkU6TY7IB42e5Qu0mK+PKvS NuasNqok4hupxrptgMznP+ZMhuFd5tKJld+F++PT3JP6+Vh1PQ7T+df80UwanCqArnRA Hs03M5I60M8kVFOmVboNc+kkqbd0ey+g/kZkbf5p/BZEx92sshJ8DI9z+bci44VCSE/M hVn1d5F8rOXaiGaeoNcvhtiDdADbHTLQnAnbvtJm8quZtzNGzUhF7vBcXAJ1xeBpHZw8 Io1A== X-Gm-Message-State: ALoCoQnifDZjV1bG86RbIUqSXydozfHXJrg0iO5urIIMuZiZsWB/dL6dgUXFnfi1SiQIyG5j9SDN X-Received: by 10.66.186.65 with SMTP id fi1mr12715516pac.51.1424400318489; Thu, 19 Feb 2015 18:45:18 -0800 (PST) Received: from omicron.ozlabs.ibm.com (bh02i525f01.au.ibm.com. [202.81.18.30]) by mx.google.com with ESMTPSA id nq16sm14800954pdb.85.2015.02.19.18.45.15 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Feb 2015 18:45:18 -0800 (PST) From: Daniel Axtens To: skiboot@lists.ozlabs.org Date: Fri, 20 Feb 2015 13:45:07 +1100 Message-Id: <1424400307-13664-4-git-send-email-dja@axtens.net> X-Mailer: git-send-email 2.1.4 In-Reply-To: <1424400307-13664-1-git-send-email-dja@axtens.net> References: <1424400307-13664-1-git-send-email-dja@axtens.net> Subject: [Skiboot] [PATCH 3/3] atoi/atol should assume base 10, not autodetect base. X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" The behaviour of atoi/atol on glibc (and according to the spec) is to assume base 10, not to autodetect the base. Signed-off-by: Daniel Axtens Reviewed-by: Cyril Bur --- libc/stdlib/atoi.c | 2 +- libc/stdlib/atol.c | 2 +- libc/test/run-stdlib.c | 11 +++++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/libc/stdlib/atoi.c b/libc/stdlib/atoi.c index d2fb33b..444c05a 100644 --- a/libc/stdlib/atoi.c +++ b/libc/stdlib/atoi.c @@ -14,5 +14,5 @@ int atoi(const char *str) { - return strtol(str, NULL, 0); + return strtol(str, NULL, 10); } diff --git a/libc/stdlib/atol.c b/libc/stdlib/atol.c index a6aa47b..e73c7d4 100644 --- a/libc/stdlib/atol.c +++ b/libc/stdlib/atol.c @@ -14,5 +14,5 @@ long atol(const char *str) { - return strtol(str, NULL, 0); + return strtol(str, NULL, 10); } diff --git a/libc/test/run-stdlib.c b/libc/test/run-stdlib.c index 98c79b7..1f3a2e1 100644 --- a/libc/test/run-stdlib.c +++ b/libc/test/run-stdlib.c @@ -39,15 +39,18 @@ int main(void) assert(atoi(buf) == 42); assert(atoi("42isthemagicnumber") == 42); - /* our atoi recognises hex! */ - assert(atoi("0x800") == 0x800); - /* But not with a duplicate prefix */ - assert(atoi("0x0x800") == 0); + /* atoi is base 10 only */ + assert(atoi("0x800") == 0); /* atol - ensure it recognises longs */ assert(atol("2147483648") == 2147483648); assert(atol("-2147483649") == -2147483649); + /* strtol detects hex */ + assert(strtol("0x800", NULL, 0) == 0x800); + /* But not with a duplicate prefix */ + assert(strtol("0x0x800", NULL, 0) == 0); + /* strtol - invalid/weird bases */ assert(strtol("z", NULL, -1) == 0); assert(strtol("11111", NULL, 1) == 0);