isc_time_nowplusinterval was using different code than the
rest of functions in the time.c. Replace custom overflow logic
with ckd_add macro.
return ISC_R_UNEXPECTED;
}
- /*
- * Ensure the resulting seconds value fits in the size of an
- * unsigned int.
- */
- if ((unsigned int)ts.tv_sec > UINT_MAX - i->seconds) {
+ /* Seconds */
+ if (ckd_add(&t->seconds, ts.tv_sec, i->seconds)) {
return ISC_R_RANGE;
}
- t->seconds = ts.tv_sec + i->seconds;
+ /* Nanoseconds */
t->nanoseconds = ts.tv_nsec + i->nanoseconds;
if (t->nanoseconds >= NS_PER_SEC) {
- t->seconds++;
+ if (t->seconds == UINT_MAX) {
+ return ISC_R_RANGE;
+ }
t->nanoseconds -= NS_PER_SEC;
+ t->seconds++;
}
return ISC_R_SUCCESS;