]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
Suppress division by zero warning
authorTony Finch <dot@dotat.at>
Wed, 5 Oct 2022 11:31:42 +0000 (12:31 +0100)
committerTony Finch <dot@dotat.at>
Wed, 5 Oct 2022 11:31:42 +0000 (12:31 +0100)
Coverity is optimistic that we might do thousands of hashes in less
than a microsecond.

    /tests/bench/siphash.c: 54 in main()
    48      count++;
    49      }
    50
    51      isc_time_now_hires(&finish);
    52
    53      us = isc_time_microdiff(&finish, &start);
    >>>     CID 358309:  Integer handling issues  (DIVIDE_BY_ZERO)
    >>>     In expression "count * 1000UL / us", division by expression "us" which may be zero has undefined behavior.
    54      printf("%f us wide-lower len %3zu, %7llu kh/s (%llx)\n",
    55             (double)us / 1000000.0, len,
    56             (unsigned long long)(count * 1000 / us),
    57             (unsigned long long)sum);
    58      }
    59

tests/bench/siphash.c

index 36f3ffad8be0212bb142845c9aa77a7590f5783c..1e9a7f41d90b7e1ca4e947d90d5f7aec532ec5d2 100644 (file)
@@ -23,6 +23,8 @@
 
 #define SIZE (1024 * 1024)
 
+#define KILOHASHES(count, us) ((us) == 0 ? 0.0 : ((count)*1000.0 / (us)))
+
 int
 main(void) {
        static uint8_t bytes[SIZE];
@@ -51,9 +53,8 @@ main(void) {
                isc_time_now_hires(&finish);
 
                us = isc_time_microdiff(&finish, &start);
-               printf("%f us wide-lower len %3zu, %7llu kh/s (%llx)\n",
-                      (double)us / 1000000.0, len,
-                      (unsigned long long)(count * 1000 / us),
+               printf("%f us wide-lower len %3zu, %7.0f kh/s (%llx)\n",
+                      (double)us / 1000000.0, len, KILOHASHES(count, us),
                       (unsigned long long)sum);
        }
 
@@ -76,9 +77,8 @@ main(void) {
                isc_time_now_hires(&finish);
 
                us = isc_time_microdiff(&finish, &start);
-               printf("%f us wide-icase len %3zu, %7llu kh/s (%llx)\n",
-                      (double)us / 1000000.0, len,
-                      (unsigned long long)(count * 1000 / us),
+               printf("%f us wide-icase len %3zu, %7.0f kh/s (%llx)\n",
+                      (double)us / 1000000.0, len, KILOHASHES(count, us),
                       (unsigned long long)sum);
        }
        for (size_t len = 256; len > 0; len = len * 4 / 5) {
@@ -100,9 +100,8 @@ main(void) {
                isc_time_now_hires(&finish);
 
                us = isc_time_microdiff(&finish, &start);
-               printf("%f us wide-bytes len %3zu, %7llu kh/s (%llx)\n",
-                      (double)us / 1000000.0, len,
-                      (unsigned long long)(count * 1000 / us),
+               printf("%f us wide-bytes len %3zu, %7.0f kh/s (%llx)\n",
+                      (double)us / 1000000.0, len, KILOHASHES(count, us),
                       (unsigned long long)sum);
        }
 
@@ -126,9 +125,8 @@ main(void) {
                isc_time_now_hires(&finish);
 
                us = isc_time_microdiff(&finish, &start);
-               printf("%f us half-lower len %3zu, %7llu kh/s (%llx)\n",
-                      (double)us / 1000000.0, len,
-                      (unsigned long long)(count * 1000 / us),
+               printf("%f us half-lower len %3zu, %7.0f kh/s (%llx)\n",
+                      (double)us / 1000000.0, len, KILOHASHES(count, us),
                       (unsigned long long)sum);
        }
 
@@ -151,9 +149,8 @@ main(void) {
                isc_time_now_hires(&finish);
 
                us = isc_time_microdiff(&finish, &start);
-               printf("%f us half-icase len %3zu, %7llu kh/s (%llx)\n",
-                      (double)us / 1000000.0, len,
-                      (unsigned long long)(count * 1000 / us),
+               printf("%f us half-icase len %3zu, %7.0f kh/s (%llx)\n",
+                      (double)us / 1000000.0, len, KILOHASHES(count, us),
                       (unsigned long long)sum);
        }
 
@@ -176,9 +173,8 @@ main(void) {
                isc_time_now_hires(&finish);
 
                us = isc_time_microdiff(&finish, &start);
-               printf("%f us half-bytes len %3zu, %7llu kh/s (%llx)\n",
-                      (double)us / 1000000.0, len,
-                      (unsigned long long)(count * 1000 / us),
+               printf("%f us half-bytes len %3zu, %7.0f kh/s (%llx)\n",
+                      (double)us / 1000000.0, len, KILOHASHES(count, us),
                       (unsigned long long)sum);
        }
 }