mirror of
https://github.com/morgan9e/systemd
synced 2026-04-16 01:16:10 +09:00
time-util: use usec_add() and usec_sub_unsigned()
And move the check with USEC_TIMESTAMP_FORMATTABLE_MAX at the end, as usec_add() can handle overflow correctly.
This commit is contained in:
@@ -882,20 +882,17 @@ from_tm:
|
||||
if (x < 0)
|
||||
return -EINVAL;
|
||||
|
||||
usec = (usec_t) x * USEC_PER_SEC + x_usec;
|
||||
if (usec > USEC_TIMESTAMP_FORMATTABLE_MAX)
|
||||
return -EINVAL;
|
||||
usec = usec_add(x * USEC_PER_SEC, x_usec);
|
||||
|
||||
finish:
|
||||
if (usec + plus < usec) /* overflow? */
|
||||
return -EINVAL;
|
||||
usec += plus;
|
||||
if (usec > USEC_TIMESTAMP_FORMATTABLE_MAX)
|
||||
usec = usec_add(usec, plus);
|
||||
|
||||
if (usec < minus)
|
||||
return -EINVAL;
|
||||
|
||||
if (usec >= minus)
|
||||
usec -= minus;
|
||||
else
|
||||
usec = usec_sub_unsigned(usec, minus);
|
||||
|
||||
if (usec > USEC_TIMESTAMP_FORMATTABLE_MAX)
|
||||
return -EINVAL;
|
||||
|
||||
if (ret)
|
||||
|
||||
Reference in New Issue
Block a user