Skip to content

Commit 9c1f780

Browse files
committed
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.
1 parent 9a41621 commit 9c1f780

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

src/os/win32/ngx_win32_config.h

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -217,15 +217,26 @@ typedef int sig_atomic_t;
217217
#define NGX_PTR_SIZE 8
218218
#define NGX_SIZE_T_LEN (sizeof("-9223372036854775808") - 1)
219219
#define NGX_MAX_SIZE_T_VALUE 9223372036854775807
220-
#define NGX_TIME_T_LEN (sizeof("-9223372036854775808") - 1)
221-
#define NGX_TIME_T_SIZE 8
222-
#define NGX_MAX_TIME_T_VALUE 9223372036854775807
223220

224221
#else
225222

226223
#define NGX_PTR_SIZE 4
227224
#define NGX_SIZE_T_LEN (sizeof("-2147483648") - 1)
228225
#define NGX_MAX_SIZE_T_VALUE 2147483647
226+
227+
#endif
228+
229+
230+
#if (defined _WIN64 || (_MSC_VER >= 1400 && !defined _USE_32BIT_TIME_T))
231+
232+
/* MSVC 2005 uses 64-bit time_t on 32-bit platforms by default */
233+
234+
#define NGX_TIME_T_LEN (sizeof("-9223372036854775808") - 1)
235+
#define NGX_TIME_T_SIZE 8
236+
#define NGX_MAX_TIME_T_VALUE 9223372036854775807
237+
238+
#else
239+
229240
#define NGX_TIME_T_LEN (sizeof("-2147483648") - 1)
230241
#define NGX_TIME_T_SIZE 4
231242
#define NGX_MAX_TIME_T_VALUE 2147483647

0 commit comments

Comments
 (0)