Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-20.2 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5174DC4338F for ; Sat, 24 Jul 2021 15:04:55 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AD70060E9C for ; Sat, 24 Jul 2021 15:04:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org AD70060E9C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3D4C982EE9; Sat, 24 Jul 2021 17:04:47 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="AHtjVlvc"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6551B82F12; Sat, 24 Jul 2021 17:04:24 +0200 (CEST) Received: from mail-ot1-x335.google.com (mail-ot1-x335.google.com [IPv6:2607:f8b0:4864:20::335]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 632E582BD7 for ; Sat, 24 Jul 2021 17:03:53 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-ot1-x335.google.com with SMTP id 48-20020a9d0bb30000b02904cd671b911bso5179095oth.1 for ; Sat, 24 Jul 2021 08:03:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=FANTxLeeSMPkupRE6kZCx2m0kTB+wQAxNCQTbJ4r8QE=; b=AHtjVlvcFr2ToR9sLBjhBigLA6ZPOT80udOadw+eMzCoa58GsjkfzI75UScckNrhyk nprvkvdsckEeKNIrBpVuQ/Cav98hkz12C9IyMP+I8QWIv74G1AVYbM2QZG9i+5gonY9Y 4X0w96qoB8EN6wcdp6H0dhim6DBqIxNJlQCG8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=FANTxLeeSMPkupRE6kZCx2m0kTB+wQAxNCQTbJ4r8QE=; b=boJGNXSt11kCpilRBoTsJmdj4nLa75GWb4mT7CJ8qw3tDB2ggFiqs/nzEuC0FlNaGB TFh+s/nb3t7zebaf3zIFNNxdxXwP/ma0L/QNKmwTTWa1n4wm1VqBWRU9D0SZCk2qJipZ hmsgkh/27BNkP/rzwHMo8mAhK8fQhNCFdQYg6fg5F3xCrbQDDFsCnY0vu3RjUHb152Hj bZTPrB/uKZtr5XWPQOThP8hmMJGM3ng3J0pA5WFoJP7E60X6DBgwE5WyD/+Np6oN+fl2 wKiqaTDYNjugTOf2cEr+K6199hU7rskuMah9MowGRE2Tbx1nvpeWBLGWPXq7Io6tgykb QNsA== X-Gm-Message-State: AOAM531pRBmeMdzRrlkhvMMjm1qq9PfObbuU5doy2ccMQCNER6gtQRy/ dIMAV7Avjqz0yckEqRfL/xZWH8orddz/jzu9 X-Google-Smtp-Source: ABdhPJw2uD8QF49BEA9Qf8Js2we/hHuoTjHQ+9ON0gPzDIhq3mF7yuivA5pxTt00oyg/yqe5k2sTNQ== X-Received: by 2002:a05:6830:1c74:: with SMTP id s20mr6765404otg.104.1627139031230; Sat, 24 Jul 2021 08:03:51 -0700 (PDT) Received: from kiwi.bld.corp.google.com (c-67-190-101-114.hsd1.co.comcast.net. [67.190.101.114]) by smtp.gmail.com with ESMTPSA id w190sm6704082oif.17.2021.07.24.08.03.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 24 Jul 2021 08:03:50 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Tom Rini , "Jonathan A . Kollasch" , Marek Vasut , Heinrich Schuchardt , =?UTF-8?q?Marek=20Beh=C3=BAn?= , Eugeniu Rosca , Roland Gaudig , Stefan Herbrechtsmeier , Sean Anderson , Simon Glass Subject: [PATCH v2 05/14] lib: Drop unnecessary check for hex digit Date: Sat, 24 Jul 2021 09:03:32 -0600 Message-Id: <20210724150341.243074-6-sjg@chromium.org> X-Mailer: git-send-email 2.32.0.432.gabb21c7263-goog In-Reply-To: <20210724150341.243074-1-sjg@chromium.org> References: <20210724150341.243074-1-sjg@chromium.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean If we see 0x then we can assume this is the start of a hex value. It does not seem necessary to check for a hex digit after that since it will happen when parsing the value anyway. Drop this check to simplify the code and reduce size. Add a few more test cases for when a 0x prefix is used. Signed-off-by: Simon Glass --- (no changes since v1) lib/strto.c | 2 +- test/str_ut.c | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/strto.c b/lib/strto.c index f4fb3faf2fa..ab6867a963f 100644 --- a/lib/strto.c +++ b/lib/strto.c @@ -18,7 +18,7 @@ static const char *_parse_integer_fixup_radix(const char *s, unsigned int *base) { if (*base == 0) { if (s[0] == '0') { - if (tolower(s[1]) == 'x' && isxdigit(s[2])) + if (tolower(s[1]) == 'x') *base = 16; else *base = 8; diff --git a/test/str_ut.c b/test/str_ut.c index 19f2c127135..8133b213bfa 100644 --- a/test/str_ut.c +++ b/test/str_ut.c @@ -84,6 +84,8 @@ static int str_simple_strtoul(struct unit_test_state *uts) /* Base 10 and base 16 */ ut_assertok(run_strtoul(uts, str2, 10, 1099, 4, upper)); ut_assertok(run_strtoul(uts, str2, 16, 0x1099ab, 6, upper)); + ut_assertok(run_strtoul(uts, str3, 16, 0xb, 3, upper)); + ut_assertok(run_strtoul(uts, str3, 10, 0, 1, upper)); /* Invalid string */ ut_assertok(run_strtoul(uts, str1, 10, 0, 0, upper)); -- 2.32.0.432.gabb21c7263-goog