2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-29 13:38:26 +00:00

Change the NS_PER_SEC (and friends) from enum to static const

New version of clang (19) has introduced a stricter checks when mixing
integer (and float types) with enums.  In this case, we used enum {}
as C17 doesn't have constexpr yet.  Change the time conversion constants
to be static const unsigned int instead of enum values.
This commit is contained in:
Ondřej Surý 2024-08-14 16:10:18 +02:00
parent 9c06717429
commit b03e90e0d4
5 changed files with 20 additions and 16 deletions

View File

@ -2176,9 +2176,9 @@ main(int argc, char *argv[]) {
now = isc_time_now();
if (isc_time_seconds(&start) == isc_time_seconds(&now))
{
int us = US_PER_SEC -
(isc_time_nanoseconds(&now) /
NS_PER_US);
unsigned int us = US_PER_SEC -
(isc_time_nanoseconds(&now) /
NS_PER_US);
if (us > US_PER_MS) {
usleep(us - US_PER_MS);
}

View File

@ -15,19 +15,21 @@
/*! \file */
#include <inttypes.h>
#include <time.h>
#include <isc/lang.h>
#include <isc/types.h>
enum {
MS_PER_SEC = 1000, /*%< Milliseonds per second. */
US_PER_MS = 1000, /*%< Microseconds per millisecond. */
US_PER_SEC = 1000 * 1000, /*%< Microseconds per second. */
NS_PER_US = 1000, /*%< Nanoseconds per microsecond. */
NS_PER_MS = 1000 * 1000, /*%< Nanoseconds per millisecond. */
NS_PER_SEC = 1000 * 1000 * 1000, /*%< Nanoseconds per second. */
};
/*
* Define various time conversion constants.
*/
static const unsigned int MS_PER_SEC = 1000;
static const unsigned int US_PER_MS = 1000;
static const unsigned int NS_PER_US = 1000;
static const unsigned int US_PER_SEC = 1000 * 1000;
static const unsigned int NS_PER_MS = 1000 * 1000;
static const unsigned int NS_PER_SEC = 1000 * 1000 * 1000;
/*
* ISC_FORMATHTTPTIMESTAMP_SIZE needs to be 30 in C locale and potentially

View File

@ -40,7 +40,8 @@ isc_stdtime_now(void) {
if (clock_gettime(CLOCKSOURCE, &ts) == -1) {
FATAL_SYSERROR(errno, "clock_gettime()");
}
INSIST(ts.tv_sec > 0 && ts.tv_nsec >= 0 && ts.tv_nsec < NS_PER_SEC);
INSIST(ts.tv_sec > 0 && ts.tv_nsec >= 0 &&
ts.tv_nsec < (long)NS_PER_SEC);
return ((isc_stdtime_t)ts.tv_sec);
}

View File

@ -86,7 +86,8 @@ time_now(clockid_t clock) {
struct timespec ts;
RUNTIME_CHECK(clock_gettime(clock, &ts) == 0);
INSIST(ts.tv_sec >= 0 && ts.tv_nsec >= 0 && ts.tv_nsec < NS_PER_SEC);
INSIST(ts.tv_sec >= 0 && ts.tv_nsec >= 0 &&
ts.tv_nsec < (long)NS_PER_SEC);
/*
* Ensure the tv_sec value fits in t->seconds.
@ -135,7 +136,7 @@ isc_time_nowplusinterval(isc_time_t *t, const isc_interval_t *i) {
return (ISC_R_UNEXPECTED);
}
if (ts.tv_sec < 0 || ts.tv_nsec < 0 || ts.tv_nsec >= NS_PER_SEC) {
if (ts.tv_sec < 0 || ts.tv_nsec < 0 || ts.tv_nsec >= (long)NS_PER_SEC) {
return (ISC_R_UNEXPECTED);
}

View File

@ -203,8 +203,8 @@ void
dns_test_nap(uint32_t usec) {
struct timespec ts;
ts.tv_sec = usec / 1000000;
ts.tv_nsec = (usec % 1000000) * 1000;
ts.tv_sec = usec / (long)US_PER_SEC;
ts.tv_nsec = (usec % (long)US_PER_SEC) * (long)NS_PER_US;
nanosleep(&ts, NULL);
}