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

Maxim Dounin mdounin at mdounin.ru
Thu Jul 10 11:16:09 UTC 2025


# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1752146087 -10800
#      Thu Jul 10 14:14:47 2025 +0300
# Node ID a66da54900004f1e8509a6a50786707ab192472c
# Parent  918faf0c610d6eaec6ade0bb5f2ca379b74f0365
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.

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