[nginx] Win32: fixed time_t size for 32-bit builds with MSVC.

Maxim Dounin mdounin at mdounin.ru
Sat Jul 19 02:59:15 UTC 2025


details:   http://freenginx.org/hg/nginx/rev/8d1dd903e480
branches:  
changeset: 9395:8d1dd903e480
user:      Maxim Dounin <mdounin at mdounin.ru>
date:      Sat Jul 19 05:57:34 2025 +0300
description:
Win32: fixed time_t size for 32-bit builds with MSVC.

Starting with MSVC 2005, 64-bit time_t is used by default, including
32-bit builds (unless _USE_32BIT_TIME_T is explicitly defined).  However,
the code assumed 32-bit time_t.

With current code, this shouldn't cause any negative effects, as various
related sizes are only used for values which are expected to fit into
32 bits.  Still, using correct size is obviously preferred, and also
will work after 2038.

Fix is to explicitly check MSVC version, and assume 64-bit time_t for
recent enough versions.

diffstat:

 src/os/win32/ngx_win32_config.h |  17 ++++++++++++++---
 1 files changed, 14 insertions(+), 3 deletions(-)

diffs (33 lines):

diff --git a/src/os/win32/ngx_win32_config.h b/src/os/win32/ngx_win32_config.h
--- a/src/os/win32/ngx_win32_config.h
+++ b/src/os/win32/ngx_win32_config.h
@@ -217,15 +217,26 @@ typedef int                 sig_atomic_t
 #define NGX_PTR_SIZE            8
 #define NGX_SIZE_T_LEN          (sizeof("-9223372036854775808") - 1)
 #define NGX_MAX_SIZE_T_VALUE    9223372036854775807
+
+#else
+
+#define NGX_PTR_SIZE            4
+#define NGX_SIZE_T_LEN          (sizeof("-2147483648") - 1)
+#define NGX_MAX_SIZE_T_VALUE    2147483647
+
+#endif
+
+
+#if (defined _WIN64 || (_MSC_VER >= 1400 && !defined _USE_32BIT_TIME_T))
+
+/* MSVC 2005 uses 64-bit time_t on 32-bit platforms by default */
+
 #define NGX_TIME_T_LEN          (sizeof("-9223372036854775808") - 1)
 #define NGX_TIME_T_SIZE         8
 #define NGX_MAX_TIME_T_VALUE    9223372036854775807
 
 #else
 
-#define NGX_PTR_SIZE            4
-#define NGX_SIZE_T_LEN          (sizeof("-2147483648") - 1)
-#define NGX_MAX_SIZE_T_VALUE    2147483647
 #define NGX_TIME_T_LEN          (sizeof("-2147483648") - 1)
 #define NGX_TIME_T_SIZE         4
 #define NGX_MAX_TIME_T_VALUE    2147483647


More information about the nginx-devel mailing list