Core: avoid potential underflow in ngx_gmtime().

The underflow may happen for small argument values.  Normally the code is
optimized by the compiler, which elimitaes the undeflow.  Even if the
underflow happens, the followup addition will also eliminate it.  The
change reorders operations to avoid the underflow in any case.

Found by Coverity (CID 1605495).
This commit is contained in:
Roman Arutyunyan 2025-03-05 17:08:36 +04:00
parent af0978ef69
commit b857b3415f

View File

@ -360,7 +360,7 @@ ngx_gmtime(time_t t, ngx_tm_t *tp)
*/
/* days since March 1, 1 BC */
days = days - (31 + 28) + 719527;
days = days + 719527 - (31 + 28);
/*
* The "days" should be adjusted to 1 only, however, some March 1st's go