From cce01f538fb4d6ae8c13c88cfc0d3caf5baca833 Mon Sep 17 00:00:00 2001 From: Laszlo Ersek Date: Wed, 17 Jul 2019 00:18:51 +0200 Subject: [PATCH] MdePkg/BaseLib: Base64Decode(): don't declare variables in nested blocks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The EDK II C Coding Standards Specification (v2.20) strongly discourages variable declarations in nested block scope: 5 Source Files 5.4 Code File Structure 5.4.1 Scoping Rules 5.4.1.1 Scope > Block (local) Scope > > [...] > > Data declarations may follow the opening brace of a compound statement, > regardless of nesting depth, and before any code generating statements > have been entered. Other than at the outermost block of a function body, > this type of declaration is strongly discouraged. Hoist such variable declarations in Base64Decode() to the outermost function scope. Cc: Liming Gao Cc: Michael D Kinney Cc: Philippe Mathieu-Daudé Cc: Zhichao Gao Fixes: 35e242b698cdc6205e99a6d6a188bf27fecf9fb4 Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1980 Reported-by: Zhichao Gao Signed-off-by: Laszlo Ersek Reviewed-by: Rebecca Cran Reviewed-by: Liming Gao Reviewed-by: Philippe Mathieu-Daude Tested-by: Philippe Mathieu-Daude --- MdePkg/Library/BaseLib/String.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/MdePkg/Library/BaseLib/String.c b/MdePkg/Library/BaseLib/String.c index 6198ccbc96..45198373f2 100644 --- a/MdePkg/Library/BaseLib/String.c +++ b/MdePkg/Library/BaseLib/String.c @@ -1978,6 +1978,9 @@ Base64Decode ( UINT32 Accumulator; UINTN OriginalDestinationSize; UINTN SourceIndex; + CHAR8 SourceChar; + UINT32 Base64Value; + UINT8 DestinationOctet; if (DestinationSize == NULL) { return RETURN_INVALID_PARAMETER; @@ -2054,10 +2057,6 @@ Base64Decode ( // Decoding loop. // for (SourceIndex = 0; SourceIndex < SourceSize; SourceIndex++) { - CHAR8 SourceChar; - UINT32 Base64Value; - UINT8 DestinationOctet; - SourceChar = Source[SourceIndex]; //