[openssl-dev] [openssl.org #3995] [PATCH] Fix VS2008 "implicitly converted to 64 bits" build warning

David Woodhouse via RT rt at openssl.org
Thu Aug 6 18:22:36 UTC 2015


When building with Visual Studio 2008, I get the following warning:

C4334: '<<' : result of 32-bit shift implicitly converted to 64 bits
(was 64-bit shift intended?)

If '1UL' is an unsigned 32-bit value, the result of shifting it by more
than 32 bits is *undefined*. The compiler isn't obliged to convert it
to a 64-bit value for us — hence the warning. We're lucky it noticed,
in fact.

Make the value explicitly 64-bit before doing the shift, and everything
should be OK. We do it by casting to (uint64_t) since support for the
ULL suffix isn't ubiquitous,

---
In fact perhaps this could be expressed differently as 
   if (N >> (16 * r))
but I figured I'd leave it in basically its original form.

 crypto/evp/scrypt.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/crypto/evp/scrypt.c b/crypto/evp/scrypt.c
index 09dfdf2..4254abf 100644
--- a/crypto/evp/scrypt.c
+++ b/crypto/evp/scrypt.c
@@ -227,7 +227,7 @@ int EVP_PBE_scrypt(const char *pass, size_t passlen,
      */
 
     if (16 * r <= LOG2_UINT64_MAX) {
-        if (N >= (1UL << (16 * r)))
+        if (N >= (((uint64_t)1) << (16 * r)))
             return 0;
     }
 
-- 
2.4.3

-- 
David Woodhouse                            Open Source Technology Centre
David.Woodhouse at intel.com                              Intel Corporation

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 5691 bytes
Desc: not available
URL: <http://mta.openssl.org/pipermail/openssl-dev/attachments/20150806/72691251/attachment.bin>
-------------- next part --------------
_______________________________________________
openssl-bugs-mod mailing list
openssl-bugs-mod at openssl.org
https://mta.openssl.org/mailman/listinfo/openssl-bugs-mod


More information about the openssl-dev mailing list