From patchwork Fri Feb 20 02:45:06 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Axtens X-Patchwork-Id: 441824 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id EFC1714017C for ; Fri, 20 Feb 2015 13:45:19 +1100 (AEDT) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id D38CD1A0E65 for ; Fri, 20 Feb 2015 13:45:19 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Received: from mail-pd0-x229.google.com (mail-pd0-x229.google.com [IPv6:2607:f8b0:400e:c02::229]) (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 7C39A1A0ECA for ; Fri, 20 Feb 2015 13:45:17 +1100 (AEDT) Received: by pdev10 with SMTP id v10so4334067pde.7 for ; Thu, 19 Feb 2015 18:45:15 -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=FUGvFDy0aCZvAMP/TSKgVziuCwHBxXNdhNNhJjQzQTQ=; b=JlMzh9uo2rI928VMEDqD1gkSnLWoQJIxCqRQoWchbVcMERepJNOeRO37M+FfKrP+W3 innbF2Mx64aeK2pxS6duptJBf2I0L6ylTO8wF76thikIku2FkUKc2JayoqDRTsIUuBeo UkXUu1OSVa+JIGMxHAxxRGqFIzHrMav0R/Ddc= 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=FUGvFDy0aCZvAMP/TSKgVziuCwHBxXNdhNNhJjQzQTQ=; b=CXOZOlJVEX2P+coGt48Q0TYsm8M8es2skhHzK+VN/dtlYTt8Ppbt/8omW3+sA8gRZf mlqnRHUUPCgYUZW838dcGLF8LVNTzZOQpNF9LtQjBR1Ep8qyjYUt0g/1TOoftHipYu/m 3f8K5mUWb+xDMiDhZufxsOawBgOgHgQY9HKT0yZlBvDkppwOIwhRslbuVSUuHJCLmK2N Fd+hDcENOMzI3o/zy/XQDYCRjQZW1c8zcDlluy56GybkpAW7ZKA4PKz0m+9bx01Boj2f 8qx2F4UmqNKqYo9fpw84zC+1Rmx1S86LzIghOSNZhlcKVBaaVjEpCtH0nzsebLaCRnHs Dgow== X-Gm-Message-State: ALoCoQmk/AMUkN9GWPK8ZEBPVUiSVE6ssczvpW9+35ENJQ2IX14kkExsN6IrAdfJkQSxSXrceoo0 X-Received: by 10.70.38.163 with SMTP id h3mr12607443pdk.95.1424400315429; Thu, 19 Feb 2015 18:45:15 -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.12 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 19 Feb 2015 18:45:14 -0800 (PST) From: Daniel Axtens To: skiboot@lists.ozlabs.org Date: Fri, 20 Feb 2015 13:45:06 +1100 Message-Id: <1424400307-13664-3-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 2/3] Don't recognise a double hex prefix (0x0xNN) as valid. 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" When autodetecting the base, the code would strip hex prefixes twice. Now the string is not modified in the detection stage. Signed-off-by: Daniel Axtens Reviewed-by: Cyril Bur --- libc/stdlib/strtol.c | 2 -- libc/stdlib/strtoul.c | 2 -- libc/test/run-stdlib.c | 7 +++---- 3 files changed, 3 insertions(+), 8 deletions(-) diff --git a/libc/stdlib/strtol.c b/libc/stdlib/strtol.c index 474597a..e6d4da3 100644 --- a/libc/stdlib/strtol.c +++ b/libc/stdlib/strtol.c @@ -53,8 +53,6 @@ long int strtol(const char *S, char **PTR,int BASE) if ((**PTR == '0') && (*((*PTR)+1) == 'x')) { BASE = 16; - (*PTR)++; - (*PTR)++; } else { diff --git a/libc/stdlib/strtoul.c b/libc/stdlib/strtoul.c index 754e7db..8472668 100644 --- a/libc/stdlib/strtoul.c +++ b/libc/stdlib/strtoul.c @@ -46,8 +46,6 @@ unsigned long int strtoul(const char *S, char **PTR,int BASE) if ((**PTR == '0') && (*((*PTR)+1) == 'x')) { BASE = 16; - (*PTR)++; - (*PTR)++; } else { diff --git a/libc/test/run-stdlib.c b/libc/test/run-stdlib.c index bb64790..98c79b7 100644 --- a/libc/test/run-stdlib.c +++ b/libc/test/run-stdlib.c @@ -41,8 +41,8 @@ int main(void) /* our atoi recognises hex! */ assert(atoi("0x800") == 0x800); - /* Really weird hex! */ - assert(atoi("0x0x800") == 0x800); + /* But not with a duplicate prefix */ + assert(atoi("0x0x800") == 0); /* atol - ensure it recognises longs */ assert(atol("2147483648") == 2147483648); @@ -73,8 +73,7 @@ int main(void) /* strtoul - autodetection of base */ assert(strtoul(" 123456", NULL, 0) == 123456); assert(strtoul("0x800", NULL, 0) == 0x800); - /* Again, really weird hex */ - assert(strtoul("0x0x800", NULL, 0) == 0x800); + assert(strtoul("0x0x800", NULL, 0) == 0); /* strtoul - weird/invalid bases */ assert(strtoul("z", NULL, -1) == 0);