From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=209.132.183.28; helo=mx1.redhat.com; envelope-from=lersek@redhat.com; receiver=edk2-devel@lists.01.org Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id B2A8E20347160 for ; Fri, 20 Oct 2017 10:08:28 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E3C9481DED; Fri, 20 Oct 2017 17:12:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com E3C9481DED Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx01.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=lersek@redhat.com Received: from lacos-laptop-7.usersys.redhat.com (ovpn-120-150.rdu2.redhat.com [10.10.120.150]) by smtp.corp.redhat.com (Postfix) with ESMTP id 72A5C5D762; Fri, 20 Oct 2017 17:12:06 +0000 (UTC) To: Peter Jones References: <20171020151018.785-1-pjones@redhat.com> Cc: edk2-devel@lists.01.org, "Shi, Steven" , Qin Long , Ting Ye From: Laszlo Ersek Message-ID: <0a2c301c-58a8-ecf7-8d1a-40dd5ab8bc8e@redhat.com> Date: Fri, 20 Oct 2017 19:12:05 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 In-Reply-To: <20171020151018.785-1-pjones@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Fri, 20 Oct 2017 17:12:08 +0000 (UTC) Subject: Re: [PATCH v1 1/1] CryptoPkg/BaseCryptLib: remove some duplicate initializations. X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 20 Oct 2017 17:08:28 -0000 Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit (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 > --- > 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 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