]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
Fix types of the csrand_interval() API
authorAlejandro Colomar <alx@kernel.org>
Fri, 30 Dec 2022 17:50:21 +0000 (18:50 +0100)
committerSerge Hallyn <serge@hallyn.com>
Sat, 28 Jan 2023 03:48:37 +0000 (21:48 -0600)
We were always casting the result to u_long.  Better just use that type
in the function.  Since we're returning u_long, it makes sense to also
specify the input as u_long.  In fact, that'll help for doing bitwise
operations inside this function.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
libmisc/salt.c

index 58b0879f6f6a83e78603f9c777214bf7d09b0e5c..fd28145c7cbb5e5301ca391f698545fc8bc53b17 100644 (file)
@@ -94,7 +94,7 @@ static long read_random_bytes (void);
 static /*@observer@*/const char *gensalt (size_t salt_size);
 #endif /* !USE_XCRYPT_GENSALT */
 #if defined(USE_SHA_CRYPT) || defined(USE_BCRYPT)
-static long csrand_interval (long min, long max);
+static unsigned long csrand_interval (unsigned long min, unsigned long max);
 #endif /* USE_SHA_CRYPT || USE_BCRYPT */
 #ifdef USE_SHA_CRYPT
 static /*@observer@*/unsigned long SHA_get_salt_rounds (/*@null@*/const int *prefered_rounds);
@@ -163,7 +163,7 @@ end:
  *
  * It favors slightly the higher numbers.
  */
-static long csrand_interval (long min, long max)
+static unsigned long csrand_interval (unsigned long min, unsigned long max)
 {
        double drand;
        long ret;
@@ -207,7 +207,7 @@ static /*@observer@*/unsigned long SHA_get_salt_rounds (/*@null@*/const int *pre
                                max_rounds = min_rounds;
                        }
 
-                       rounds = (unsigned long) csrand_interval (min_rounds, max_rounds);
+                       rounds = csrand_interval (min_rounds, max_rounds);
                }
        } else if (0 == *prefered_rounds) {
                rounds = SHA_ROUNDS_DEFAULT;
@@ -280,7 +280,7 @@ static /*@observer@*/unsigned long BCRYPT_get_salt_rounds (/*@null@*/const int *
                                max_rounds = min_rounds;
                        }
 
-                       rounds = (unsigned long) csrand_interval (min_rounds, max_rounds);
+                       rounds = csrand_interval (min_rounds, max_rounds);
                }
        } else if (0 == *prefered_rounds) {
                rounds = B_ROUNDS_DEFAULT;