[PATCH 2 of 4] Win32: cleaned up most of C4244 warnings with 32-bit compilation

Maxim Dounin mdounin at mdounin.ru
Sat May 31 20:23:16 UTC 2025


# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1748666368 -10800
#      Sat May 31 07:39:28 2025 +0300
# Node ID 1ce7a2381e6a880636779800499a0bf99ca7bd6e
# Parent  9228d497cb38bd5fda2177380c3eee372a3ddbfd
Win32: cleaned up most of C4244 warnings with 32-bit compilation.

C4244 warnings (conversion from 'type1' to 'type2', possible loss of data)
were disabled in 6861:e4590dfd97ff as part of introducing support for
64-bit compilation with MSVC.  Still, these warnings remain useful
in some cases.  Additionally, they explain multiple otherwise unneeded type
casts in the code.

This change resolves most of the warnings as observed during 32-bit
compilation with C4244 warnings enabled by introducing additional type
casts, in most cases already used in other parts of the code in similar
constructs.

diff --git a/src/core/ngx_inet.c b/src/core/ngx_inet.c
--- a/src/core/ngx_inet.c
+++ b/src/core/ngx_inet.c
@@ -1286,7 +1286,7 @@ ngx_inet_add_addr(ngx_pool_t *pool, ngx_
 
         ngx_memcpy(sa, sockaddr, socklen);
 
-        ngx_inet_set_port(sa, u->port + i);
+        ngx_inet_set_port(sa, u->port + (in_port_t) i);
 
         switch (sa->sa_family) {
 
diff --git a/src/core/ngx_times.c b/src/core/ngx_times.c
--- a/src/core/ngx_times.c
+++ b/src/core/ngx_times.c
@@ -332,7 +332,7 @@ ngx_gmtime(time_t t, ngx_tm_t *tp)
         t = 0;
     }
 
-    days = t / 86400;
+    days = (ngx_uint_t) t / 86400;
     sec = t % 86400;
 
     /*
diff --git a/src/http/ngx_http_file_cache.c b/src/http/ngx_http_file_cache.c
--- a/src/http/ngx_http_file_cache.c
+++ b/src/http/ngx_http_file_cache.c
@@ -387,7 +387,8 @@ ngx_http_file_cache_open(ngx_http_reques
 
     if (of.is_directio) {
 
-        c->body_start = ngx_align(c->body_start, clcf->directio_alignment);
+        c->body_start = ngx_align(c->body_start,
+                                  (size_t) clcf->directio_alignment);
 
         c->buf = ngx_calloc_buf(r->pool);
         if (c->buf == NULL) {
@@ -395,7 +396,7 @@ ngx_http_file_cache_open(ngx_http_reques
         }
 
         c->buf->start = ngx_pmemalign(r->pool, c->body_start,
-                                      clcf->directio_alignment);
+                                      (size_t) clcf->directio_alignment);
         if (c->buf->start == NULL) {
             return NGX_ERROR;
         }
diff --git a/src/http/ngx_http_request_body.c b/src/http/ngx_http_request_body.c
--- a/src/http/ngx_http_request_body.c
+++ b/src/http/ngx_http_request_body.c
@@ -1220,7 +1220,8 @@ ngx_http_request_body_chunked_filter(ngx
                         }
 
                     } else {
-                        ngx_memmove(b->last, cl->buf->pos, rb->chunked->size);
+                        ngx_memmove(b->last, cl->buf->pos,
+                                    (size_t) rb->chunked->size);
                         b->last += rb->chunked->size;
                         cl->buf->pos += rb->chunked->size;
                         rb->chunked->size = 0;



More information about the nginx-devel mailing list