Discussion:
[PATCH] Suppress unused value warnings casue by HOST_cl2
Doug Kwan
2014-10-10 19:50:08 UTC
Permalink
This patch add void casts before some uses of HOST_cl2 to avoid unused value
warnings in gcc. There are already similar void casts in other uses of
HOST_cl2.
---
crypto/md5/md5_dgst.c | 30 +++++++++++++++---------------
crypto/sha/sha256.c | 34 +++++++++++++++++-----------------
crypto/sha/sha_locl.h | 2 +-
3 files changed, 33 insertions(+), 33 deletions(-)

diff --git a/crypto/md5/md5_dgst.c b/crypto/md5/md5_dgst.c
index beace63..2bf6ec0 100644
--- a/crypto/md5/md5_dgst.c
+++ b/crypto/md5/md5_dgst.c
@@ -105,22 +105,22 @@ void md5_block_data_order (MD5_CTX *c, const void *data_, size_t num)

for (;num--;)
{
- HOST_c2l(data,l); X( 0)=l; HOST_c2l(data,l); X( 1)=l;
+ (void)HOST_c2l(data,l); X( 0)=l; (void)HOST_c2l(data,l); X( 1)=l;
/* Round 0 */
- R0(A,B,C,D,X( 0), 7,0xd76aa478L); HOST_c2l(data,l); X( 2)=l;
- R0(D,A,B,C,X( 1),12,0xe8c7b756L); HOST_c2l(data,l); X( 3)=l;
- R0(C,D,A,B,X( 2),17,0x242070dbL); HOST_c2l(data,l); X( 4)=l;
- R0(B,C,D,A,X( 3),22,0xc1bdceeeL); HOST_c2l(data,l); X( 5)=l;
- R0(A,B,C,D,X( 4), 7,0xf57c0fafL); HOST_c2l(data,l); X( 6)=l;
- R0(D,A,B,C,X( 5),12,0x4787c62aL); HOST_c2l(data,l); X( 7)=l;
- R0(C,D,A,B,X( 6),17,0xa8304613L); HOST_c2l(data,l); X( 8)=l;
- R0(B,C,D,A,X( 7),22,0xfd469501L); HOST_c2l(data,l); X( 9)=l;
- R0(A,B,C,D,X( 8), 7,0x698098d8L); HOST_c2l(data,l); X(10)=l;
- R0(D,A,B,C,X( 9),12,0x8b44f7afL); HOST_c2l(data,l); X(11)=l;
- R0(C,D,A,B,X(10),17,0xffff5bb1L); HOST_c2l(data,l); X(12)=l;
- R0(B,C,D,A,X(11),22,0x895cd7beL); HOST_c2l(data,l); X(13)=l;
- R0(A,B,C,D,X(12), 7,0x6b901122L); HOST_c2l(data,l); X(14)=l;
- R0(D,A,B,C,X(13),12,0xfd987193L); HOST_c2l(data,l); X(15)=l;
+ R0(A,B,C,D,X( 0), 7,0xd76aa478L); (void)HOST_c2l(data,l); X( 2)=l;
+ R0(D,A,B,C,X( 1),12,0xe8c7b756L); (void)HOST_c2l(data,l); X( 3)=l;
+ R0(C,D,A,B,X( 2),17,0x242070dbL); (void)HOST_c2l(data,l); X( 4)=l;
+ R0(B,C,D,A,X( 3),22,0xc1bdceeeL); (void)HOST_c2l(data,l); X( 5)=l;
+ R0(A,B,C,D,X( 4), 7,0xf57c0fafL); (void)HOST_c2l(data,l); X( 6)=l;
+ R0(D,A,B,C,X( 5),12,0x4787c62aL); (void)HOST_c2l(data,l); X( 7)=l;
+ R0(C,D,A,B,X( 6),17,0xa8304613L); (void)HOST_c2l(data,l); X( 8)=l;
+ R0(B,C,D,A,X( 7),22,0xfd469501L); (void)HOST_c2l(data,l); X( 9)=l;
+ R0(A,B,C,D,X( 8), 7,0x698098d8L); (void)HOST_c2l(data,l); X(10)=l;
+ R0(D,A,B,C,X( 9),12,0x8b44f7afL); (void)HOST_c2l(data,l); X(11)=l;
+ R0(C,D,A,B,X(10),17,0xffff5bb1L); (void)HOST_c2l(data,l); X(12)=l;
+ R0(B,C,D,A,X(11),22,0x895cd7beL); (void)HOST_c2l(data,l); X(13)=l;
+ R0(A,B,C,D,X(12), 7,0x6b901122L); (void)HOST_c2l(data,l); X(14)=l;
+ R0(D,A,B,C,X(13),12,0xfd987193L); (void)HOST_c2l(data,l); X(15)=l;
R0(C,D,A,B,X(14),17,0xa679438eL);
R0(B,C,D,A,X(15),22,0x49b40821L);
/* Round 1 */
diff --git a/crypto/sha/sha256.c b/crypto/sha/sha256.c
index dbd5eb7..8240007 100644
--- a/crypto/sha/sha256.c
+++ b/crypto/sha/sha256.c
@@ -164,7 +164,7 @@ static void sha256_block_data_order (SHA256_CTX *ctx, const void *in, size_t num

for (i=0;i<16;i++)
{
- HOST_c2l(data,l); T1 = X[i] = l;
+ (void)HOST_c2l(data,l); T1 = X[i] = l;
T1 += h + Sigma1(e) + Ch(e,f,g) + K256[i];
T2 = Sigma0(a) + Maj(a,b,c);
h = g; g = f; f = e; e = d + T1;
@@ -242,22 +242,22 @@ static void sha256_block_data_order (SHA256_CTX *ctx, const void *in, size_t num
{
SHA_LONG l;

- HOST_c2l(data,l); T1 = X[0] = l; ROUND_00_15(0,a,b,c,d,e,f,g,h);
- HOST_c2l(data,l); T1 = X[1] = l; ROUND_00_15(1,h,a,b,c,d,e,f,g);
- HOST_c2l(data,l); T1 = X[2] = l; ROUND_00_15(2,g,h,a,b,c,d,e,f);
- HOST_c2l(data,l); T1 = X[3] = l; ROUND_00_15(3,f,g,h,a,b,c,d,e);
- HOST_c2l(data,l); T1 = X[4] = l; ROUND_00_15(4,e,f,g,h,a,b,c,d);
- HOST_c2l(data,l); T1 = X[5] = l; ROUND_00_15(5,d,e,f,g,h,a,b,c);
- HOST_c2l(data,l); T1 = X[6] = l; ROUND_00_15(6,c,d,e,f,g,h,a,b);
- HOST_c2l(data,l); T1 = X[7] = l; ROUND_00_15(7,b,c,d,e,f,g,h,a);
- HOST_c2l(data,l); T1 = X[8] = l; ROUND_00_15(8,a,b,c,d,e,f,g,h);
- HOST_c2l(data,l); T1 = X[9] = l; ROUND_00_15(9,h,a,b,c,d,e,f,g);
- HOST_c2l(data,l); T1 = X[10] = l; ROUND_00_15(10,g,h,a,b,c,d,e,f);
- HOST_c2l(data,l); T1 = X[11] = l; ROUND_00_15(11,f,g,h,a,b,c,d,e);
- HOST_c2l(data,l); T1 = X[12] = l; ROUND_00_15(12,e,f,g,h,a,b,c,d);
- HOST_c2l(data,l); T1 = X[13] = l; ROUND_00_15(13,d,e,f,g,h,a,b,c);
- HOST_c2l(data,l); T1 = X[14] = l; ROUND_00_15(14,c,d,e,f,g,h,a,b);
- HOST_c2l(data,l); T1 = X[15] = l; ROUND_00_15(15,b,c,d,e,f,g,h,a);
+ (void)HOST_c2l(data,l); T1 = X[0] = l; ROUND_00_15(0,a,b,c,d,e,f,g,h);
+ (void)HOST_c2l(data,l); T1 = X[1] = l; ROUND_00_15(1,h,a,b,c,d,e,f,g);
+ (void)HOST_c2l(data,l); T1 = X[2] = l; ROUND_00_15(2,g,h,a,b,c,d,e,f);
+ (void)HOST_c2l(data,l); T1 = X[3] = l; ROUND_00_15(3,f,g,h,a,b,c,d,e);
+ (void)HOST_c2l(data,l); T1 = X[4] = l; ROUND_00_15(4,e,f,g,h,a,b,c,d);
+ (void)HOST_c2l(data,l); T1 = X[5] = l; ROUND_00_15(5,d,e,f,g,h,a,b,c);
+ (void)HOST_c2l(data,l); T1 = X[6] = l; ROUND_00_15(6,c,d,e,f,g,h,a,b);
+ (void)HOST_c2l(data,l); T1 = X[7] = l; ROUND_00_15(7,b,c,d,e,f,g,h,a);
+ (void)HOST_c2l(data,l); T1 = X[8] = l; ROUND_00_15(8,a,b,c,d,e,f,g,h);
+ (void)HOST_c2l(data,l); T1 = X[9] = l; ROUND_00_15(9,h,a,b,c,d,e,f,g);
+ (void)HOST_c2l(data,l); T1 = X[10] = l; ROUND_00_15(10,g,h,a,b,c,d,e,f);
+ (void)HOST_c2l(data,l); T1 = X[11] = l; ROUND_00_15(11,f,g,h,a,b,c,d,e);
+ (void)HOST_c2l(data,l); T1 = X[12] = l; ROUND_00_15(12,e,f,g,h,a,b,c,d);
+ (void)HOST_c2l(data,l); T1 = X[13] = l; ROUND_00_15(13,d,e,f,g,h,a,b,c);
+ (void)HOST_c2l(data,l); T1 = X[14] = l; ROUND_00_15(14,c,d,e,f,g,h,a,b);
+ (void)HOST_c2l(data,l); T1 = X[15] = l; ROUND_00_15(15,b,c,d,e,f,g,h,a);
}

for (i=16;i<64;i+=8)
diff --git a/crypto/sha/sha_locl.h b/crypto/sha/sha_locl.h
index 0baeb0f..5d75044 100644
--- a/crypto/sha/sha_locl.h
+++ b/crypto/sha/sha_locl.h
@@ -399,7 +399,7 @@ static void HASH_BLOCK_DATA_ORDER (SHA_CTX *c, const void *p, size_t num)
for (;;)
{
for (i=0;i<16;i++)
- { HOST_c2l(data,l); X[i]=l; BODY_00_15(X[i]); }
+ { (void)HOST_c2l(data,l); X[i]=l; BODY_00_15(X[i]); }
for (i=0;i<4;i++)
{ BODY_16_19(X[i], X[i+2], X[i+8], X[(i+13)&15]); }
for (;i<24;i++)
--
2.1.0.rc2.206.gedb03e5

______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List openssl-***@openssl.org
Automated List Manager ***@openssl.org
Salz, Rich
2014-10-10 21:18:55 UTC
Permalink
Is there any time that the value of HOST_cl2 is used? Could we just add the (void) cast to the macro definition?

--
Principal Security Engineer, Akamai Technologies
IM: ***@jabber.me Twitter: RichSalz
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List openssl-***@openssl.org
Automated List Manager ***@openssl.org
Doug Kwan (關振德)
2014-10-10 21:37:14 UTC
Permalink
Post by Salz, Rich
Is there any time that the value of HOST_cl2 is used? Could we just add the (void) cast to the macro definition?
As fas as I can see there is none. We can add the (void) cast to the
macro definition and remove the existing void casts at the use sites.
I added void casts in use sites only because that is the existing way.
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List openssl-***@openssl.org
Automated List Manager ***@openssl.org
Salz, Rich
2014-10-10 21:39:47 UTC
Permalink
Let's fix it the right way. :)

--
Principal Security Engineer, Akamai Technologies
IM: ***@jabber.me Twitter: RichSalz
:��I"Ϯ��r�m���� (����Z+�7�zZ)���1���x ��h����W^��^��%��
Doug Kwan (關振德)
2014-10-10 21:51:30 UTC
Permalink
Post by Salz, Rich
Let's fix it the right way. :)
--
Principal Security Engineer, Akamai Technologies
No problem, I will submit another patch as you suggested. :-)

Personally I prefer having HOST_c2l() returning something useful
instead of storing to a location. That looks more natural since the
result is a scalar.

#defined HOST_c2l(c) (c += 4, \

((((unsigned long)c[-4]) << 24) | \

(((unsigned long)c[-3]) << 16) | \

(((unsigned long)c[-2]) << 8) | \

((unsigned long)c[-1])))
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List openssl-***@openssl.org
Automated List Manager ***@openssl.org
Doug Kwan (關振德)
2014-10-13 22:57:14 UTC
Permalink
Post by Salz, Rich
Let's fix it the right way. :)
--
Principal Security Engineer, Akamai Technologies
I changed the definitions of HOST_c2l on different platforms and
removed the unneeded void casts. This is tested on Linux running on
x86_64, powerpc64le and aarch64.

-Doug
Doug Kwan (關振德)
2014-10-20 18:49:56 UTC
Permalink
ping?
Post by Doug Kwan (關振德)
Post by Salz, Rich
Let's fix it the right way. :)
--
Principal Security Engineer, Akamai Technologies
I changed the definitions of HOST_c2l on different platforms and
removed the unneeded void casts. This is tested on Linux running on
x86_64, powerpc64le and aarch64.
-Doug
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List openssl-***@openssl.org
Automated List Manager ***@openssl.org
Salz, Rich
2014-10-20 19:00:21 UTC
Permalink
It will go into master, post-1.0.2

--
Principal Security Engineer, Akamai Technologies
-----Original Message-----
Sent: Monday, October 20, 2014 8:50 PM
Subject: Re: [PATCH] Suppress unused value warnings casue by HOST_cl2
ping?
On Mon, Oct 13, 2014 at 3:57 PM, Doug Kwan (關振德)
Post by Doug Kwan (關振德)
Post by Salz, Rich
Let's fix it the right way. :)
--
Principal Security Engineer, Akamai Technologies
I changed the definitions of HOST_c2l on different platforms and
removed the unneeded void casts. This is tested on Linux running on
x86_64, powerpc64le and aarch64.
-Doug
__________________________________________________________
____________
OpenSSL Project http://www.openssl.org
:��I"Ϯ��r�m���� (����Z+�7�zZ)���1���x ��h����W^��^��%��
Andy Polyakov
2014-10-23 12:00:58 UTC
Permalink
Post by Salz, Rich
Is there any time that the value of HOST_cl2 is used? Could we just
add the (void) cast to the macro definition?
It's not only about whether or not it's actually used, but even question
of style. Macros are *preferred* to be expressions so that they can be
used as part of other expression. What I'm saying is that while void-ing
macro does solve this particular problem, it would be kind of "cowardly"
way out. The correct solution is to remove ',l' as was also suggested.
This way compiler doesn't complain and macro is still compliant with
style guidelines.
______________________________________________________________________
OpenSSL Project http://www.openssl.org
Development Mailing List openssl-***@openssl.org
Automated List Manager ***@openssl.org
Andy Polyakov
2014-10-23 12:10:08 UTC
Permalink
Post by Andy Polyakov
The correct solution is to remove ',l' as was also suggested.
I mean like attached.
Post by Andy Polyakov
This way compiler doesn't complain and macro is still compliant with
style guidelines.
Loading...