public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] MdePkg/BaseLib: Base64Decode(): don't declare variables in nested blocks
@ 2019-07-16 22:59 Laszlo Ersek
  2019-07-16 23:03 ` [edk2-devel] " rebecca
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Laszlo Ersek @ 2019-07-16 22:59 UTC (permalink / raw)
  To: edk2-devel-groups-io
  Cc: Liming Gao, Michael D Kinney, Philippe Mathieu-Daudé,
	Zhichao Gao

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 <liming.gao@intel.com>
Cc: Michael D Kinney <michael.d.kinney@intel.com>
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
Cc: Zhichao Gao <zhichao.gao@intel.com>
Fixes: 35e242b698cdc6205e99a6d6a188bf27fecf9fb4
Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1980
Reported-by: Zhichao Gao <zhichao.gao@intel.com>
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
---

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];
 
     //
-- 
2.19.1.3.g30247aa5d201


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [edk2-devel] [PATCH] MdePkg/BaseLib: Base64Decode(): don't declare variables in nested blocks
  2019-07-16 22:59 [PATCH] MdePkg/BaseLib: Base64Decode(): don't declare variables in nested blocks Laszlo Ersek
@ 2019-07-16 23:03 ` rebecca
  2019-07-17  1:00 ` Liming Gao
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: rebecca @ 2019-07-16 23:03 UTC (permalink / raw)
  To: devel, lersek
  Cc: Liming Gao, Michael D Kinney, Philippe Mathieu-Daudé,
	Zhichao Gao

On 2019-07-16 16:59, Laszlo Ersek wrote:
>
> Hoist such variable declarations in Base64Decode() to the outermost
> function scope.
>
> Cc: Liming Gao <liming.gao@intel.com>
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
> Cc: Zhichao Gao <zhichao.gao@intel.com>
> Fixes: 35e242b698cdc6205e99a6d6a188bf27fecf9fb4
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1980
> Reported-by: Zhichao Gao <zhichao.gao@intel.com>
> Signed-off-by: Laszlo Ersek <lersek@redhat.com>

Reviewed-by: Rebecca Cran <rebecca@bsdio.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] MdePkg/BaseLib: Base64Decode(): don't declare variables in nested blocks
  2019-07-16 22:59 [PATCH] MdePkg/BaseLib: Base64Decode(): don't declare variables in nested blocks Laszlo Ersek
  2019-07-16 23:03 ` [edk2-devel] " rebecca
@ 2019-07-17  1:00 ` Liming Gao
  2019-07-17  7:03 ` Philippe Mathieu-Daudé
  2019-07-17 14:42 ` [edk2-devel] " Laszlo Ersek
  3 siblings, 0 replies; 5+ messages in thread
From: Liming Gao @ 2019-07-17  1:00 UTC (permalink / raw)
  To: Laszlo Ersek, edk2-devel-groups-io
  Cc: Kinney, Michael D, Philippe Mathieu-Daudé, Gao, Zhichao

Reviewed-by: Liming Gao <liming.gao@intel.com>

> -----Original Message-----
> From: Laszlo Ersek [mailto:lersek@redhat.com]
> Sent: Wednesday, July 17, 2019 6:59 AM
> To: edk2-devel-groups-io <devel@edk2.groups.io>
> Cc: Gao, Liming <liming.gao@intel.com>; Kinney, Michael D <michael.d.kinney@intel.com>; Philippe Mathieu-Daudé
> <philmd@redhat.com>; Gao, Zhichao <zhichao.gao@intel.com>
> Subject: [PATCH] MdePkg/BaseLib: Base64Decode(): don't declare variables in nested blocks
> 
> 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 <liming.gao@intel.com>
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
> Cc: Zhichao Gao <zhichao.gao@intel.com>
> Fixes: 35e242b698cdc6205e99a6d6a188bf27fecf9fb4
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1980
> Reported-by: Zhichao Gao <zhichao.gao@intel.com>
> Signed-off-by: Laszlo Ersek <lersek@redhat.com>
> ---
> 
> 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];
> 
>      //
> --
> 2.19.1.3.g30247aa5d201


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] MdePkg/BaseLib: Base64Decode(): don't declare variables in nested blocks
  2019-07-16 22:59 [PATCH] MdePkg/BaseLib: Base64Decode(): don't declare variables in nested blocks Laszlo Ersek
  2019-07-16 23:03 ` [edk2-devel] " rebecca
  2019-07-17  1:00 ` Liming Gao
@ 2019-07-17  7:03 ` Philippe Mathieu-Daudé
  2019-07-17 14:42 ` [edk2-devel] " Laszlo Ersek
  3 siblings, 0 replies; 5+ messages in thread
From: Philippe Mathieu-Daudé @ 2019-07-17  7:03 UTC (permalink / raw)
  To: Laszlo Ersek, edk2-devel-groups-io
  Cc: Liming Gao, Michael D Kinney, Zhichao Gao

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 <liming.gao@intel.com>
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
> Cc: Zhichao Gao <zhichao.gao@intel.com>
> Fixes: 35e242b698cdc6205e99a6d6a188bf27fecf9fb4
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1980
> Reported-by: Zhichao Gao <zhichao.gao@intel.com>
> Signed-off-by: Laszlo Ersek <lersek@redhat.com>
> ---
> 
> 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 <philmd@redhat.com>
Tested-by: Philippe Mathieu-Daude <philmd@redhat.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [edk2-devel] [PATCH] MdePkg/BaseLib: Base64Decode(): don't declare variables in nested blocks
  2019-07-16 22:59 [PATCH] MdePkg/BaseLib: Base64Decode(): don't declare variables in nested blocks Laszlo Ersek
                   ` (2 preceding siblings ...)
  2019-07-17  7:03 ` Philippe Mathieu-Daudé
@ 2019-07-17 14:42 ` Laszlo Ersek
  3 siblings, 0 replies; 5+ messages in thread
From: Laszlo Ersek @ 2019-07-17 14:42 UTC (permalink / raw)
  To: edk2-devel-groups-io
  Cc: Liming Gao, Michael D Kinney, Philippe Mathieu-Daudé,
	Zhichao Gao, Rebecca Cran

On 07/17/19 00:59, 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 <liming.gao@intel.com>
> Cc: Michael D Kinney <michael.d.kinney@intel.com>
> Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
> Cc: Zhichao Gao <zhichao.gao@intel.com>
> Fixes: 35e242b698cdc6205e99a6d6a188bf27fecf9fb4
> Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=1980
> Reported-by: Zhichao Gao <zhichao.gao@intel.com>
> Signed-off-by: Laszlo Ersek <lersek@redhat.com>
> ---
> 
> 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(-)

Thank you all for the reviews / testing; patch pushed as commit
cce01f538fb4.

Thanks!
Laszlo

> 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];
>  
>      //
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-07-17 14:42 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-07-16 22:59 [PATCH] MdePkg/BaseLib: Base64Decode(): don't declare variables in nested blocks Laszlo Ersek
2019-07-16 23:03 ` [edk2-devel] " rebecca
2019-07-17  1:00 ` Liming Gao
2019-07-17  7:03 ` Philippe Mathieu-Daudé
2019-07-17 14:42 ` [edk2-devel] " Laszlo Ersek

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox