From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: redhat.com, ip: 209.85.221.66, mailfrom: philmd@redhat.com) Received: from mail-wr1-f66.google.com (mail-wr1-f66.google.com [209.85.221.66]) by groups.io with SMTP; Wed, 17 Jul 2019 00:04:02 -0700 Received: by mail-wr1-f66.google.com with SMTP id p17so23464202wrf.11 for ; Wed, 17 Jul 2019 00:04:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:openpgp:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=BxXLEf9RgW1+cLeLXnV/1dpfTCDO0Betkg+BmNodF30=; b=d/DwvLS5iFBcgvWQYsgSUn/OTjz4D7DeIRi1ko1cG5+ATPIYnraLUiGhgp0396rXbE Z9QtpTzXhs37+uuCKTAD7/R+IYq2f/K9ZdQMvDRnUUCCdsLTjqzUIKZ8Pdsn4Ib9gqD2 Rmyt1LXonrZBIh90aFSDy5qkWb5F+vi9bUWlaMz9HEm7w3/XmxCporD+S2godEkgOqFE n1jfHOv5Za2muMcSWiHEO2MrPvEpHa1dYA+TidaUOwEWTD6LkNt70pGiNsypJ3gBfe02 N2cvDD7j0ZGOEi2l2IsJ1/2iM2ko8rAm6rcGXicpbtLtcggr15YNHV+iFYEp+EUrC9HF EGSw== X-Gm-Message-State: APjAAAU0PirOTLw/i1DS6lx9PAsP3pcMhFUJeV9QXsZAe6yy9pmQRzAj 9ZilqxgvkJat8J0hgiGw5TN0Fw== X-Google-Smtp-Source: APXvYqxWfqgw4xmflR/+XkYtGvzzbNcAKZ4VVWhGdFy2ziOaHn4mWaYQCZ8arO2MK/QNE06PERIAJg== X-Received: by 2002:adf:fa42:: with SMTP id y2mr20883643wrr.170.1563347040929; Wed, 17 Jul 2019 00:04:00 -0700 (PDT) Return-Path: Received: from [192.168.1.38] (62.red-83-42-61.dynamicip.rima-tde.net. [83.42.61.62]) by smtp.gmail.com with ESMTPSA id q18sm23271164wrw.36.2019.07.17.00.03.59 (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Wed, 17 Jul 2019 00:04:00 -0700 (PDT) Subject: Re: [PATCH] MdePkg/BaseLib: Base64Decode(): don't declare variables in nested blocks To: Laszlo Ersek , edk2-devel-groups-io Cc: Liming Gao , Michael D Kinney , Zhichao Gao References: <20190716225926.19732-1-lersek@redhat.com> From: =?UTF-8?B?UGhpbGlwcGUgTWF0aGlldS1EYXVkw6k=?= Openpgp: id=89C1E78F601EE86C867495CBA2A3FD6EDEADC0DE; url=http://pgp.mit.edu/pks/lookup?op=get&search=0xA2A3FD6EDEADC0DE Message-ID: Date: Wed, 17 Jul 2019 09:03:59 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20190716225926.19732-1-lersek@redhat.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit On 7/17/19 12:59 AM, Laszlo Ersek wrote: > 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 > --- > > Notes: > Repo: https://github.com/lersek/edk2.git > Branch: b64_decode_no_nested_bz1980 > > 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 6198ccbc9672..45198373f25c 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]; > > // > Reviewed-by: Philippe Mathieu-Daude Tested-by: Philippe Mathieu-Daude