You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by wr...@apache.org on 2005/01/05 20:01:22 UTC

svn commit: r124243 - /apr/apr/trunk/random/unix/sha2.c

Author: wrowe
Date: Wed Jan  5 11:01:20 2005
New Revision: 124243

URL: http://svn.apache.org/viewcvs?view=rev&rev=124243
Log:

  Clean up 4 extranious emits.  Because of the modulo operator, these
  becomes safe casts to unsigned.

Modified:
   apr/apr/trunk/random/unix/sha2.c

Modified: apr/apr/trunk/random/unix/sha2.c
Url: http://svn.apache.org/viewcvs/apr/apr/trunk/random/unix/sha2.c?view=diff&rev=124243&p1=apr/apr/trunk/random/unix/sha2.c&r1=124242&p2=apr/apr/trunk/random/unix/sha2.c&r2=124243
==============================================================================
--- apr/apr/trunk/random/unix/sha2.c	(original)
+++ apr/apr/trunk/random/unix/sha2.c	Wed Jan  5 11:01:20 2005
@@ -458,7 +458,8 @@
         /* Sanity check: */
         assert(context != (SHA256_CTX*)0 && data != (sha2_byte*)0);
 
-        usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH;
+        usedspace = (unsigned int)((context->bitcount >> 3) 
+                                 % SHA256_BLOCK_LENGTH);
         if (usedspace > 0) {
                 /* Calculate how much free space is available in the buffer */
                 freespace = SHA256_BLOCK_LENGTH - usedspace;
@@ -504,7 +505,8 @@
 
         /* If no digest buffer is passed, we don't bother doing this: */
         if (digest != (sha2_byte*)0) {
-                usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH;
+                usedspace = (unsigned int)((context->bitcount >> 3) 
+                                         % SHA256_BLOCK_LENGTH);
 #if !APR_IS_BIGENDIAN
                 /* Convert FROM host byte order */
                 REVERSE64(context->bitcount,context->bitcount);
@@ -780,7 +782,8 @@
         /* Sanity check: */
         assert(context != (SHA512_CTX*)0 && data != (sha2_byte*)0);
 
-        usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
+        usedspace = (unsigned int)((context->bitcount[0] >> 3) 
+                                 % SHA512_BLOCK_LENGTH);
         if (usedspace > 0) {
                 /* Calculate how much free space is available in the buffer */
                 freespace = SHA512_BLOCK_LENGTH - usedspace;
@@ -820,7 +823,8 @@
 void SHA512_Last(SHA512_CTX* context) {
         unsigned int    usedspace;
 
-        usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
+        usedspace = (unsigned int)((context->bitcount[0] >> 3) 
+                                 % SHA512_BLOCK_LENGTH);
 #if !APR_IS_BIGENDIAN
         /* Convert FROM host byte order */
         REVERSE64(context->bitcount[0],context->bitcount[0]);

Re: svn commit: r124243 - /apr/apr/trunk/random/unix/sha2.c

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
Yes, language was insufficient, it should have said something
like 'Cleanup four quadword->dword truncation warnings, the
modulo operator ensures the resulting quantity can safely 
be cast down to a dword.'

A comment in the code apologizing for the cast would also
be worthwhile, I'll do that before backporting.

If I hear no negative feedback, I'll commit Sunday with comment
to 1.0 / 0.9 so they both compile cleanly and such warnings
don't alarm end users.

Bill

At 12:19 PM 1/11/2005, Julian Foad wrote:
>William A. Rowe, Jr. wrote:
>>Can I have a second set of eyes for a reality check before
>>I backport this compile-time cleanup?
>
>It looks fine to me, if you think it is appropriate to back-port such a clean-up.
>
>The log message is rather difficult to understand.
>
>- Julian
>
>
>[...]
>>>Log:
>>>
>>>Clean up 4 extranious emits.  Because of the modulo operator, these
>>>becomes safe casts to unsigned.
>[...]
>>>-        usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH;
>>>+        usedspace = (unsigned int)((context->bitcount >> 3) +                                 % SHA256_BLOCK_LENGTH);
>[...]
>
>



Re: svn commit: r124243 - /apr/apr/trunk/random/unix/sha2.c

Posted by Julian Foad <ju...@btopenworld.com>.
William A. Rowe, Jr. wrote:
> Can I have a second set of eyes for a reality check before
> I backport this compile-time cleanup?

It looks fine to me, if you think it is appropriate to back-port such a clean-up.

The log message is rather difficult to understand.

- Julian


[...]
>>Log:
>>
>> Clean up 4 extranious emits.  Because of the modulo operator, these
>> becomes safe casts to unsigned.
[...]
>>-        usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH;
>>+        usedspace = (unsigned int)((context->bitcount >> 3) 
>>+                                 % SHA256_BLOCK_LENGTH);
[...]


Re: svn commit: r124243 - /apr/apr/trunk/random/unix/sha2.c

Posted by "William A. Rowe, Jr." <wr...@rowe-clan.net>.
Can I have a second set of eyes for a reality check before
I backport this compile-time cleanup?

Bill

At 01:01 PM 1/5/2005, wrowe@apache.org wrote:
>Author: wrowe
>Date: Wed Jan  5 11:01:20 2005
>New Revision: 124243
>
>URL: http://svn.apache.org/viewcvs?view=rev&rev=124243
>Log:
>
>  Clean up 4 extranious emits.  Because of the modulo operator, these
>  becomes safe casts to unsigned.
>
>Modified:
>   apr/apr/trunk/random/unix/sha2.c
>
>Modified: apr/apr/trunk/random/unix/sha2.c
>Url: http://svn.apache.org/viewcvs/apr/apr/trunk/random/unix/sha2.c?view=diff&rev=124243&p1=apr/apr/trunk/random/unix/sha2.c&r1=124242&p2=apr/apr/trunk/random/unix/sha2.c&r2=124243
>==============================================================================
>--- apr/apr/trunk/random/unix/sha2.c    (original)
>+++ apr/apr/trunk/random/unix/sha2.c    Wed Jan  5 11:01:20 2005
>@@ -458,7 +458,8 @@
>         /* Sanity check: */
>         assert(context != (SHA256_CTX*)0 && data != (sha2_byte*)0);
> 
>-        usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH;
>+        usedspace = (unsigned int)((context->bitcount >> 3) 
>+                                 % SHA256_BLOCK_LENGTH);
>         if (usedspace > 0) {
>                 /* Calculate how much free space is available in the buffer */
>                 freespace = SHA256_BLOCK_LENGTH - usedspace;
>@@ -504,7 +505,8 @@
> 
>         /* If no digest buffer is passed, we don't bother doing this: */
>         if (digest != (sha2_byte*)0) {
>-                usedspace = (context->bitcount >> 3) % SHA256_BLOCK_LENGTH;
>+                usedspace = (unsigned int)((context->bitcount >> 3) 
>+                                         % SHA256_BLOCK_LENGTH);
> #if !APR_IS_BIGENDIAN
>                 /* Convert FROM host byte order */
>                 REVERSE64(context->bitcount,context->bitcount);
>@@ -780,7 +782,8 @@
>         /* Sanity check: */
>         assert(context != (SHA512_CTX*)0 && data != (sha2_byte*)0);
> 
>-        usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
>+        usedspace = (unsigned int)((context->bitcount[0] >> 3) 
>+                                 % SHA512_BLOCK_LENGTH);
>         if (usedspace > 0) {
>                 /* Calculate how much free space is available in the buffer */
>                 freespace = SHA512_BLOCK_LENGTH - usedspace;
>@@ -820,7 +823,8 @@
> void SHA512_Last(SHA512_CTX* context) {
>         unsigned int    usedspace;
> 
>-        usedspace = (context->bitcount[0] >> 3) % SHA512_BLOCK_LENGTH;
>+        usedspace = (unsigned int)((context->bitcount[0] >> 3) 
>+                                 % SHA512_BLOCK_LENGTH);
> #if !APR_IS_BIGENDIAN
>         /* Convert FROM host byte order */
>         REVERSE64(context->bitcount[0],context->bitcount[0]);