From: Tony Finch Date: Wed, 5 Oct 2022 11:31:42 +0000 (+0100) Subject: Suppress division by zero warning X-Git-Tag: v9.19.6~9^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf715d488b5cba13872a1f896741b14ac3957db7;p=thirdparty%2Fbind9.git Suppress division by zero warning 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 --- diff --git a/tests/bench/siphash.c b/tests/bench/siphash.c index 36f3ffad8be..1e9a7f41d90 100644 --- a/tests/bench/siphash.c +++ b/tests/bench/siphash.c @@ -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); } }