public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: Laszlo Ersek <lersek@redhat.com>
To: Peter Jones <pjones@redhat.com>
Cc: edk2-devel@lists.01.org, "Shi, Steven" <steven.shi@intel.com>,
	Qin Long <qin.long@intel.com>, Ting Ye <ting.ye@intel.com>
Subject: Re: [PATCH v1 1/1] CryptoPkg/BaseCryptLib: remove some duplicate initializations.
Date: Fri, 20 Oct 2017 19:12:05 +0200	[thread overview]
Message-ID: <0a2c301c-58a8-ecf7-8d1a-40dd5ab8bc8e@redhat.com> (raw)
In-Reply-To: <20171020151018.785-1-pjones@redhat.com>

(adding CryptoPkg maintainers from Maintainers.txt, plus Steven for
clang)

On 10/20/17 17:10, Peter Jones wrote:
> clang-analyzer noticed this:
>
> Pk/CryptPkcs7Verify.c:600:5: warning: Value stored to 'OldSize' is never read
>     OldSize    = BufferSize;
>     ^            ~~~~~~~~~~
> Pk/CryptPkcs7Verify.c:644:5: warning: Value stored to 'OldSize' is never read
>     OldSize    = BufferSize;
>     ^            ~~~~~~~~~~
> 2 warnings generated.

Interesting; Steven runs clang (incl. clang-analyzer AFAIK) frequently,
and I don't recall an earlier report of this.

Anyway,

>
> These are each immediately followed by a loop that initializes them (to
> the same values) a second time, and are otherwise only referenced inside
> that loop, so there's just no point to these assignments at all.

I agree.

While each of both loops might fail to reach the inner assignment to
OldSize -- in case the first X509PopCertificate() call fails in the
loop, for Index=0 --, OldSize is still never read after each loop
(before another assignment to it is reached). So setting OldSize to
anything at all before the loops is superfluous.

>
> Contributed-under: TianoCore Contribution Agreement 1.1
> Signed-off-by: Peter Jones <pjones@redhat.com>
> ---
>  CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c | 2 --
>  1 file changed, 2 deletions(-)
>
> diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c
> index d564591cb7f9..bf67a1f569a2 100644
> --- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c
> +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c
> @@ -612,7 +612,6 @@ Pkcs7GetCertificatesList (
>
>    if (CtxChain != NULL) {
>      BufferSize = sizeof (UINT8);
> -    OldSize    = BufferSize;
>      CertBuf    = NULL;
>
>      for (Index = 0; ; Index++) {
> @@ -656,7 +655,6 @@ Pkcs7GetCertificatesList (
>
>    if (CtxUntrusted != NULL) {
>      BufferSize = sizeof (UINT8);
> -    OldSize    = BufferSize;
>      CertBuf    = NULL;
>
>      for (Index = 0; ; Index++) {
>

For your patch:

Reviewed-by: Laszlo Ersek <lersek@redhat.com>

Assuming the maintainers are fine with the patch as well, I suggest that
they please replace the word "initializations" with "assignments" in the
subject, to be pedantic on the C-lang level.

(Side note: I would even move OldSize to a lot tighter scope:

> diff --git a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c
> index d564591cb7f9..31a9ecd59ff6 100644
> --- a/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c
> +++ b/CryptoPkg/Library/BaseCryptLib/Pk/CryptPkcs7Verify.c
> @@ -477,7 +477,6 @@ Pkcs7GetCertificatesList (
>    UINT8            *CertBuf;
>    UINT8            *OldBuf;
>    UINTN            BufferSize;
> -  UINTN            OldSize;
>    UINT8            *SingleCert;
>    UINTN            CertSize;
>
> @@ -612,10 +611,11 @@ Pkcs7GetCertificatesList (
>
>    if (CtxChain != NULL) {
>      BufferSize = sizeof (UINT8);
> -    OldSize    = BufferSize;
>      CertBuf    = NULL;
>
>      for (Index = 0; ; Index++) {
> +      UINTN OldSize;
> +
>        Status = X509PopCertificate (CtxChain, &SingleCert, &CertSize);
>        if (!Status) {
>          break;
> @@ -656,10 +656,11 @@ Pkcs7GetCertificatesList (
>
>    if (CtxUntrusted != NULL) {
>      BufferSize = sizeof (UINT8);
> -    OldSize    = BufferSize;
>      CertBuf    = NULL;
>
>      for (Index = 0; ; Index++) {
> +      UINTN OldSize;
> +
>        Status = X509PopCertificate (CtxUntrusted, &SingleCert, &CertSize);
>        if (!Status) {
>          break;

However, many edk2 maintainers don't like tight scoping like this.)

Thanks
Laszlo


  reply	other threads:[~2017-10-20 17:08 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-10-20 15:10 [PATCH v1 1/1] CryptoPkg/BaseCryptLib: remove some duplicate initializations Peter Jones
2017-10-20 17:12 ` Laszlo Ersek [this message]
2017-10-20 18:21   ` Peter Jones
2017-10-23  3:02     ` Long, Qin
2017-10-24  7:51       ` Laszlo Ersek
2017-10-24  8:15         ` Long, Qin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0a2c301c-58a8-ecf7-8d1a-40dd5ab8bc8e@redhat.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox