From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) by mx.groups.io with SMTP id smtpd.web09.79753.1656983785871800897 for ; Mon, 04 Jul 2022 18:16:26 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@gmail.com header.s=20210112 header.b=OFcB7hJO; spf=pass (domain: gmail.com, ip: 209.85.128.41, mailfrom: pedro.falcato@gmail.com) Received: by mail-wm1-f41.google.com with SMTP id v67-20020a1cac46000000b003a1888b9d36so6409431wme.0 for ; Mon, 04 Jul 2022 18:16:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=qnXqBwpwAmx/cCcLeOwkFjGoG+L3VGqFu31ZU4aNS6Y=; b=OFcB7hJOkx1+3UXiNztMoU6fEciz+n5RxFIT6C8lB0ScqAqs/1VyzoLkl7WiesaqXb 76RNpsH440PiVP8SfXQCUgx2le6Ts1/U6BoUIgU6IwA8zCAn5R7E9eEuo4PsP69WxT+7 VwD3SCkFToslp2bY/Q1WP57bf5MgzK27XuCa28+iohE841JOmUQ2P9Ms/zngaOfc9pkK RRonj5vinKFFe1r5EmjblOsXwf5If6NtGi5T3291JPx8xRICfY97gsGl1IyHqizlVVM8 24x9H6dUtY/74W2ZuZddWPVzGch4Hxm+En/dJwuJM1u4AZCE/nvFHgqTKKFiuAxFmjg3 5kIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=qnXqBwpwAmx/cCcLeOwkFjGoG+L3VGqFu31ZU4aNS6Y=; b=5u21flTKL+eg+POyHomA6ybgWIfbTnBmgAQBPWFgW0aO+mRuwT3P1BBouenx4ctfeH V91sHgJUpl420EOr+xYxllupbj0JD2bAGsaBIXNLbJGXkCCTFQE0FHNDxJPNvRWNU0xH YyYS0PZEWphw2jlpIi26cL+RdrH0Mez8/0ktrB2VmyQTO5dGTv08yDwQL0DaOez1zbWE M052d95IzZkRghmPVLSmbzUslctmdMRk9+IC6ap5rZehTRcC9EJ+JgnzLyZKXqFdUiMp rHuqaI60aDZcJdQKtbYtMNsriLdEA/oAgm5kVL5bIb2oorntNgDeGEmsQkdE95CRNddC VGvQ== X-Gm-Message-State: AJIora8oQ9Hy5WVrQJ49aQhAt4xGLCfujpYqoE2wwVbU+jTs5aPtjWmH mYDBRIhfUgLg3JCTfpD2P3o8iFT/llXluQ== X-Google-Smtp-Source: AGRyM1sU2K8Zo114kJQIJHKl59HZ8axw9y345wzsT3bAiVPagl/6WE1JcbgmWR6bmIrBvaEcPxMlxA== X-Received: by 2002:a1c:7918:0:b0:3a0:4c75:87af with SMTP id l24-20020a1c7918000000b003a04c7587afmr35067687wme.194.1656983783967; Mon, 04 Jul 2022 18:16:23 -0700 (PDT) Return-Path: Received: from PC-PEDRO-ARCH.lan ([2001:8a0:7280:5801:9441:3dce:686c:bfc7]) by smtp.gmail.com with ESMTPSA id bg28-20020a05600c3c9c00b003a175bc9c17sm17534261wmb.42.2022.07.04.18.16.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Jul 2022 18:16:23 -0700 (PDT) From: "Pedro Falcato" To: devel@edk2.groups.io Cc: Michael D Kinney , Liming Gao , Zhiguang Liu Subject: [PATCH v2] MdePkg/BasePrintLib: Add %z specifier Date: Tue, 5 Jul 2022 02:16:22 +0100 Message-Id: <20220705011622.351454-1-pedro.falcato@gmail.com> X-Mailer: git-send-email 2.37.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=3977 %z is used in standard C99 as the printf specifier for size_t types. Add support for it so we can portably print UINTN. Cc: Michael D Kinney Cc: Liming Gao Cc: Zhiguang Liu Signed-off-by: Pedro Falcato --- MdePkg/Include/Library/PrintLib.h | 13 ++++++++----- MdePkg/Library/BasePrintLib/PrintLibInternal.c | 9 +++++++++ MdePkg/Library/BasePrintLib/PrintLibInternal.h | 1 + 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/MdePkg/Include/Library/PrintLib.h b/MdePkg/Include/Library/PrintLib.h index 8d523cac52..0d67f62d3f 100644 --- a/MdePkg/Include/Library/PrintLib.h +++ b/MdePkg/Include/Library/PrintLib.h @@ -42,6 +42,9 @@ SPDX-License-Identifier: BSD-2-Clause-Patent - L, l - The number being printed is size UINT64. Only valid for types X, x, and d. If this flag is not specified, then the number being printed is size int. + - z + - The number being printed is of size UINTN. Only valid for types X, x and d. + If this flag is not specified, then the number being printed is size int. - NOTE: All invalid flags are ignored. [width]: @@ -73,18 +76,18 @@ SPDX-License-Identifier: BSD-2-Clause-Patent using this type too by making sure bits 8..15 of the argument are set to 0. - x - The argument is an unsigned hexadecimal number. The characters used are 0..9 and - A..F. If the flag 'L' is not specified, then the argument is assumed + A..F. If the flags 'L', 'z' are not specified, then the argument is assumed to be size int. This does not follow ANSI C. - X - The argument is an unsigned hexadecimal number and the number is padded with - zeros. This is equivalent to a format string of "0x". If the flag - 'L' is not specified, then the argument is assumed to be size int. + zeros. This is equivalent to a format string of "0x". If the flags + 'L', 'z' are not specified, then the argument is assumed to be size int. This does not follow ANSI C. - d - - The argument is a signed decimal number. If the flag 'L' is not specified, + - The argument is a signed decimal number. If the flags 'L', 'z' are not specified, then the argument is assumed to be size int. - u - - The argument is a unsigned decimal number. If the flag 'L' is not specified, + - The argument is a unsigned decimal number. If the flags 'L'. 'z' are not specified, then the argument is assumed to be size int. - p - The argument is a pointer that is a (VOID *), and it is printed as an diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.c b/MdePkg/Library/BasePrintLib/PrintLibInternal.c index 42b598a432..1cd99b2213 100644 --- a/MdePkg/Library/BasePrintLib/PrintLibInternal.c +++ b/MdePkg/Library/BasePrintLib/PrintLibInternal.c @@ -720,6 +720,9 @@ BasePrintLibSPrintMarker ( case 'l': Flags |= LONG_TYPE; break; + case 'z': + Flags |= SIZET_TYPE; + break; case '*': if ((Flags & PRECISION) == 0) { Flags |= PAD_TO_WIDTH; @@ -833,6 +836,12 @@ BasePrintLibSPrintMarker ( } else { Value = BASE_ARG (BaseListMarker, int); } + } else if ((Flags & SIZET_TYPE) != 0) { + if (BaseListMarker == NULL) { + Value = VA_ARG (VaListMarker, UINTN); + } else { + Value = BASE_ARG (BaseListMarker, UINTN); + } } else { if (BaseListMarker == NULL) { Value = VA_ARG (VaListMarker, INT64); diff --git a/MdePkg/Library/BasePrintLib/PrintLibInternal.h b/MdePkg/Library/BasePrintLib/PrintLibInternal.h index 34d591c6fc..9193e6192b 100644 --- a/MdePkg/Library/BasePrintLib/PrintLibInternal.h +++ b/MdePkg/Library/BasePrintLib/PrintLibInternal.h @@ -29,6 +29,7 @@ #define ARGUMENT_REVERSED BIT12 #define COUNT_ONLY_NO_PRINT BIT13 #define UNSIGNED_TYPE BIT14 +#define SIZET_TYPE BIT15 // // Record date and time information -- 2.37.0