heimdal: Fix "assuming signed overflow doesnt occur" error
authorVolker Lendecke <vl@samba.org>
Mon, 18 Mar 2019 08:30:17 +0000 (09:30 +0100)
committerJeremy Allison <jra@samba.org>
Mon, 18 Mar 2019 19:21:24 +0000 (19:21 +0000)
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
source4/heimdal/lib/hcrypto/libtommath/bn_mp_rshd.c

index ed13ce59a4926835482f1fc8c4d402d342b3a18b..907674c41e4deb487ab22cf5d73d175386b63a53 100644 (file)
@@ -18,8 +18,6 @@
 /* shift right a certain amount of digits */
 void mp_rshd (mp_int * a, int b)
 {
-  int     x;
-
   /* if b <= 0 then ignore it */
   if (b <= 0) {
     return;
@@ -33,6 +31,7 @@ void mp_rshd (mp_int * a, int b)
 
   {
     register mp_digit *bottom, *top;
+    unsigned x, y;
 
     /* shift the digits down */
 
@@ -52,12 +51,13 @@ void mp_rshd (mp_int * a, int b)
                  /\                   |      ---->
                   \-------------------/      ---->
      */
-    for (x = 0; x < (a->used - b); x++) {
+    y = a->used - b;           /* a->used>=b checked above */
+    for (x = 0; x < y; x++) {
       *bottom++ = *top++;
     }
 
     /* zero the top digits */
-    for (; x < a->used; x++) {
+    for (; x < (unsigned)a->used; x++) {
       *bottom++ = 0;
     }
   }