From patchwork Thu Nov 29 12:31:28 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 152401 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp2320899ljp; Thu, 29 Nov 2018 04:31:54 -0800 (PST) X-Google-Smtp-Source: AFSGD/XeV4AFUFsx8A0383IUrtPrzUCbnwRFqEsV93b1CVXCZQgEbsd/nhSQuyyM1BdYMR8KK2LV X-Received: by 2002:a17:902:1103:: with SMTP id d3-v6mr1213673pla.249.1543494714170; Thu, 29 Nov 2018 04:31:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543494714; cv=none; d=google.com; s=arc-20160816; b=OnJXw3KxnSKsKLQAp656smnzBWE7Gk70yURfABqtb7Y09HFBZQFv2xgqX8fmYukrZU 26LAGO3maOUvZCXcpx+pP/3XnwYmvg+RgwGeFR9zbWIk4MUVh4W2cMV2UZpH4ZQg7Kvs hI49PhJ0EjkYPOQqgroADMPAcNki532i0I42BXMilKsHa6bTbIq2q5C0vX0X3ikbJL+g ibWd5UbiU1+JUMP3SZ/NpQkiAVic4nSy9+H3/xux4Jir4TbzW0iaMs6fal769vBDeILr Ci3aOP2xDg1AA9JVhX/StymAjTNGDY4qR4XDB/lGw2iQMAueGa1saVIF6M0wYPOMR5bh SUAQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=XqtaR148T0j7ovL1xEIy9f9TlDem7yHG6M6extyLchM=; b=eSi0tpj/tggZZwGE9tRCVwLJT8DNaf7pQtl3AMId6wVHUW8DDswPWIOBQdKOrHgjV5 hqC5N6usH0+FjB1i3DRgxhGOwwz0EqEunIBVEE9qN+m0e7Ngts+qUJ/fGk9AgSxo5Dje gUnsOdgRkKhl898hOI2reYNPnYqru04PawTOP2dNU3WRuiFUiSgr5QYuSuFhvLXlgWcm Op3gInCa0HBdxp0qS2snJ2jq94R1lt106XpkOkqgVPNXOYbWzkOwMly7N9KcuCWnnWPe +6AzfEfPGMerRaJSYIZayMFwVAwNIMqZUxxR4Rj/BIORviogkuTiJeS5OtaSZ6tBfy/N 0CNw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=cvoRufdt; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id y12si1906307pgf.527.2018.11.29.04.31.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Nov 2018 04:31:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=cvoRufdt; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3A3AA211963F1; Thu, 29 Nov 2018 04:31:44 -0800 (PST) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=2a00:1450:4864:20::430; helo=mail-wr1-x430.google.com; envelope-from=ard.biesheuvel@linaro.org; receiver=edk2-devel@lists.01.org Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 284E421CAD998 for ; Thu, 29 Nov 2018 04:31:42 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id v6so1697316wrr.12 for ; Thu, 29 Nov 2018 04:31:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mvUqSYk9dMxqvoHZt00Kgxsp+J1v4r3C9KgflUyN1nA=; b=cvoRufdt5Wx06+BUD3tI8Ekvy2sdglRmq7sKByASMSWuqHrTEi5Dba8ANpn0tGMplg g8vYOs70XfwOCNicEHfs/6fIH31HEbEO5Bd3yrWk2q/NoVZ6bgZPWyzZrI4djhDrnUCe ZPI6D8qvJyQ9lsPQ4Xk8ioXk6BKevbRu3rdfo= 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=mvUqSYk9dMxqvoHZt00Kgxsp+J1v4r3C9KgflUyN1nA=; b=Wnp/8lBpKaA3Csz5/EYOPr6nYOG28fQgPdnje+OjmQWqMrC2kgR3dh8DH0S/Hj+WyD p2xH5baLDldvg9pDMX9t1l6yak8o/iVfzkab4OEdPWHkm/7qe751Qy8iFCqb6PXMf5S1 C9KWs7jVgOoVTava9PlxuwhjlNI600krfB636fX+7hvj17Vc6gqOldDVyOA+H0GMMvtH AeAiPwP7aBKQbIXw1tf3HF250MuJYAjSYZ/MbgxtDUn91v96bfWaR8FJrAiR1/XQkkZa Z2uJuj72tlMBq5/4sV3ziNdQwve65k+f5xO+zPkWA0tdGuIbgdOBajlm1WOEEUj8qN3V eRbQ== X-Gm-Message-State: AA+aEWaXPdjFRdE/6kD52O+i8kHBk+I553yW57TFZ52d+NXKeKhOi1aW LpI6w3iM6iSg2kheC5aUwQ0Hzj8+ZGw= X-Received: by 2002:adf:80a9:: with SMTP id 38mr1178217wrl.137.1543494700308; Thu, 29 Nov 2018 04:31:40 -0800 (PST) Received: from harold.home ([2a01:cb1d:112:6f00:3580:6f80:40a7:5bdd]) by smtp.gmail.com with ESMTPSA id c7sm3089525wre.64.2018.11.29.04.31.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Nov 2018 04:31:39 -0800 (PST) From: Ard Biesheuvel To: edk2-devel@lists.01.org Date: Thu, 29 Nov 2018 13:31:28 +0100 Message-Id: <20181129123129.25095-6-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181129123129.25095-1-ard.biesheuvel@linaro.org> References: <20181129123129.25095-1-ard.biesheuvel@linaro.org> MIME-Version: 1.0 Subject: [edk2] [PATCH 5/6] BaseTools/CommonLib: get rid of 'native' type string parsing routines X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laszlo Ersek , Liming Gao Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" Parsing a string into an integer variable of the native word size is not defined for the BaseTools, since the same tools may be used to build firmware for different targets with different native word sizes. Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Ard Biesheuvel --- BaseTools/Source/C/Common/CommonLib.h | 24 --- BaseTools/Source/C/Common/CommonLib.c | 174 +------------------- 2 files changed, 5 insertions(+), 193 deletions(-) -- 2.19.1 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/BaseTools/Source/C/Common/CommonLib.h b/BaseTools/Source/C/Common/CommonLib.h index fa10fac4682a..6930d9227b87 100644 --- a/BaseTools/Source/C/Common/CommonLib.h +++ b/BaseTools/Source/C/Common/CommonLib.h @@ -250,16 +250,6 @@ StrSize ( CONST CHAR16 *String ); -UINTN -StrHexToUintn ( - CONST CHAR16 *String - ); - -UINTN -StrDecimalToUintn ( - CONST CHAR16 *String - ); - UINT64 StrHexToUint64 ( CONST CHAR16 *String @@ -277,13 +267,6 @@ StrHexToUint64S ( UINT64 *Data ); -RETURN_STATUS -StrHexToUintnS ( - CONST CHAR16 *String, - CHAR16 **EndPointer, OPTIONAL - UINTN *Data - ); - RETURN_STATUS StrDecimalToUint64S ( CONST CHAR16 *String, @@ -291,13 +274,6 @@ StrDecimalToUint64S ( UINT64 *Data ); -RETURN_STATUS -StrDecimalToUintnS ( - CONST CHAR16 *String, - CHAR16 **EndPointer, OPTIONAL - UINTN *Data - ); - VOID * ReallocatePool ( UINTN OldSize, diff --git a/BaseTools/Source/C/Common/CommonLib.c b/BaseTools/Source/C/Common/CommonLib.c index c5e32b1292e0..9142a9a7eda3 100644 --- a/BaseTools/Source/C/Common/CommonLib.c +++ b/BaseTools/Source/C/Common/CommonLib.c @@ -882,72 +882,6 @@ InternalSafeStringNoStrOverlap ( return !InternalSafeStringIsOverlap (Str1, Size1 * sizeof(CHAR16), Str2, Size2 * sizeof(CHAR16)); } -RETURN_STATUS -StrDecimalToUintnS ( - CONST CHAR16 *String, - CHAR16 **EndPointer, OPTIONAL - UINTN *Data - ) -{ - ASSERT (((UINTN) String & BIT0) == 0); - - // - // 1. Neither String nor Data shall be a null pointer. - // - SAFE_STRING_CONSTRAINT_CHECK ((String != NULL), RETURN_INVALID_PARAMETER); - SAFE_STRING_CONSTRAINT_CHECK ((Data != NULL), RETURN_INVALID_PARAMETER); - - // - // 2. The length of String shall not be greater than RSIZE_MAX. - // - if (RSIZE_MAX != 0) { - SAFE_STRING_CONSTRAINT_CHECK ((StrnLenS (String, RSIZE_MAX + 1) <= RSIZE_MAX), RETURN_INVALID_PARAMETER); - } - - if (EndPointer != NULL) { - *EndPointer = (CHAR16 *) String; - } - - // - // Ignore the pad spaces (space or tab) - // - while ((*String == L' ') || (*String == L'\t')) { - String++; - } - - // - // Ignore leading Zeros after the spaces - // - while (*String == L'0') { - String++; - } - - *Data = 0; - - while (InternalIsDecimalDigitCharacter (*String)) { - // - // If the number represented by String overflows according to the range - // defined by UINTN, then MAX_UINTN is stored in *Data and - // RETURN_UNSUPPORTED is returned. - // - if (*Data > ((MAX_UINTN - (*String - L'0')) / 10)) { - *Data = MAX_UINTN; - if (EndPointer != NULL) { - *EndPointer = (CHAR16 *) String; - } - return RETURN_UNSUPPORTED; - } - - *Data = *Data * 10 + (*String - L'0'); - String++; - } - - if (EndPointer != NULL) { - *EndPointer = (CHAR16 *) String; - } - return RETURN_SUCCESS; -} - /** Convert a Null-terminated Unicode decimal string to a value of type UINT64. @@ -1064,9 +998,9 @@ StrDecimalToUint64S ( /** Convert a Null-terminated Unicode hexadecimal string to a value of type - UINTN. + UINT64. - This function outputs a value of type UINTN by interpreting the contents of + This function outputs a value of type UINT64 by interpreting the contents of the Unicode string specified by String as a hexadecimal number. The format of the input Unicode string String is: @@ -1091,8 +1025,8 @@ StrDecimalToUint64S ( If String has no valid hexadecimal digits in the above format, then 0 is stored at the location pointed to by Data. - If the number represented by String exceeds the range defined by UINTN, then - MAX_UINTN is stored at the location pointed to by Data. + If the number represented by String exceeds the range defined by UINT64, then + MAX_UINT64 is stored at the location pointed to by Data. If EndPointer is not NULL, a pointer to the character that stopped the scan is stored at the location pointed to by EndPointer. If String has no valid @@ -1112,86 +1046,10 @@ StrDecimalToUint64S ( characters, not including the Null-terminator. @retval RETURN_UNSUPPORTED If the number represented by String exceeds - the range defined by UINTN. + the range defined by UINT64. **/ RETURN_STATUS -StrHexToUintnS ( - CONST CHAR16 *String, - CHAR16 **EndPointer, OPTIONAL - UINTN *Data - ) -{ - ASSERT (((UINTN) String & BIT0) == 0); - - // - // 1. Neither String nor Data shall be a null pointer. - // - SAFE_STRING_CONSTRAINT_CHECK ((String != NULL), RETURN_INVALID_PARAMETER); - SAFE_STRING_CONSTRAINT_CHECK ((Data != NULL), RETURN_INVALID_PARAMETER); - - // - // 2. The length of String shall not be greater than RSIZE_MAX. - // - if (RSIZE_MAX != 0) { - SAFE_STRING_CONSTRAINT_CHECK ((StrnLenS (String, RSIZE_MAX + 1) <= RSIZE_MAX), RETURN_INVALID_PARAMETER); - } - - if (EndPointer != NULL) { - *EndPointer = (CHAR16 *) String; - } - - // - // Ignore the pad spaces (space or tab) - // - while ((*String == L' ') || (*String == L'\t')) { - String++; - } - - // - // Ignore leading Zeros after the spaces - // - while (*String == L'0') { - String++; - } - - if (InternalCharToUpper (*String) == L'X') { - if (*(String - 1) != L'0') { - *Data = 0; - return RETURN_SUCCESS; - } - // - // Skip the 'X' - // - String++; - } - - *Data = 0; - - while (InternalIsHexaDecimalDigitCharacter (*String)) { - // - // If the number represented by String overflows according to the range - // defined by UINTN, then MAX_UINTN is stored in *Data and - // RETURN_UNSUPPORTED is returned. - // - if (*Data > ((MAX_UINTN - InternalHexCharToUintn (*String)) >> 4)) { - *Data = MAX_UINTN; - if (EndPointer != NULL) { - *EndPointer = (CHAR16 *) String; - } - return RETURN_UNSUPPORTED; - } - - *Data = (*Data << 4) + InternalHexCharToUintn (*String); - String++; - } - - if (EndPointer != NULL) { - *EndPointer = (CHAR16 *) String; - } - return RETURN_SUCCESS; -} -RETURN_STATUS StrHexToUint64S ( CONST CHAR16 *String, CHAR16 **EndPointer, OPTIONAL @@ -1291,28 +1149,6 @@ StrHexToUint64 ( return Result; } -UINTN -StrDecimalToUintn ( - CONST CHAR16 *String - ) -{ - UINTN Result; - - StrDecimalToUintnS (String, (CHAR16 **) NULL, &Result); - return Result; -} - -UINTN -StrHexToUintn ( - CONST CHAR16 *String - ) -{ - UINTN Result; - - StrHexToUintnS (String, (CHAR16 **) NULL, &Result); - return Result; -} - UINTN StrSize ( CONST CHAR16 *String