changeset 5359:2fda9065d0f4

Win32: Borland C compatibility fixes. Several false positive warnings silenced, notably W8012 "Comparing signed and unsigned" (due to u_short values promoted to int), and W8072 "Suspicious pointer arithmetic" (due to large type values added to pointers). With this patch, it's now again possible to compile nginx using bcc32, with options we normally compile on win32 minus ipv6 and ssl.
author Maxim Dounin <mdounin@mdounin.ru>
date Wed, 04 Sep 2013 20:48:23 +0400
parents 670ceaba03d8
children 3d2d3e1cf427
files auto/lib/pcre/makefile.bcc src/event/ngx_event_accept.c src/http/modules/ngx_http_memcached_module.c src/http/modules/ngx_http_mp4_module.c src/http/modules/ngx_http_proxy_module.c src/http/modules/ngx_http_upstream_ip_hash_module.c src/http/ngx_http_file_cache.c src/http/ngx_http_request_body.c src/os/win32/ngx_win32_config.h
diffstat 9 files changed, 27 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/auto/lib/pcre/makefile.bcc	Wed Sep 04 20:48:22 2013 +0400
+++ b/auto/lib/pcre/makefile.bcc	Wed Sep 04 20:48:23 2013 +0400
@@ -13,8 +13,8 @@
 
 	bcc32 -c $(CFLAGS) -I. $(PCREFLAGS) pcre_*.c
 
-	> pcre.lst
-	for %n in (*.obj) do @echo +%n & >> pcre.lst
+	copy /y nul pcre.lst
+	for %n in (*.obj) do @echo +%n ^^& >> pcre.lst
 	echo + >> pcre.lst
 
 	tlib pcre.lib @pcre.lst
--- a/src/event/ngx_event_accept.c	Wed Sep 04 20:48:22 2013 +0400
+++ b/src/event/ngx_event_accept.c	Wed Sep 04 20:48:23 2013 +0400
@@ -297,7 +297,7 @@
 
         cidr = ecf->debug_connection.elts;
         for (i = 0; i < ecf->debug_connection.nelts; i++) {
-            if (cidr[i].family != c->sockaddr->sa_family) {
+            if (cidr[i].family != (ngx_uint_t) c->sockaddr->sa_family) {
                 goto next;
             }
 
--- a/src/http/modules/ngx_http_memcached_module.c	Wed Sep 04 20:48:22 2013 +0400
+++ b/src/http/modules/ngx_http_memcached_module.c	Wed Sep 04 20:48:23 2013 +0400
@@ -520,7 +520,7 @@
         return NGX_OK;
     }
 
-    last += u->length - NGX_HTTP_MEMCACHED_END;
+    last += (size_t) (u->length - NGX_HTTP_MEMCACHED_END);
 
     if (ngx_strncmp(last, ngx_http_memcached_end, b->last - last) != 0) {
         ngx_log_error(NGX_LOG_ERR, ctx->request->connection->log, 0,
--- a/src/http/modules/ngx_http_mp4_module.c	Wed Sep 04 20:48:22 2013 +0400
+++ b/src/http/modules/ngx_http_mp4_module.c	Wed Sep 04 20:48:23 2013 +0400
@@ -157,7 +157,11 @@
 #define ngx_mp4_atom_header(mp4)   (mp4->buffer_pos - 8)
 #define ngx_mp4_atom_data(mp4)     mp4->buffer_pos
 #define ngx_mp4_atom_data_size(t)  (uint64_t) (sizeof(t) - 8)
-#define ngx_mp4_atom_next(mp4, n)  mp4->buffer_pos += n; mp4->offset += n
+
+
+#define ngx_mp4_atom_next(mp4, n)                                             \
+    mp4->buffer_pos += (size_t) n;                                            \
+    mp4->offset += n
 
 
 #define ngx_mp4_set_atom_name(p, n1, n2, n3, n4)                              \
@@ -956,7 +960,7 @@
     ngx_log_debug0(NGX_LOG_DEBUG_HTTP, mp4->file.log, 0, "mp4 ftyp atom");
 
     if (atom_data_size > 1024
-        || ngx_mp4_atom_data(mp4) + atom_data_size > mp4->buffer_end)
+        || ngx_mp4_atom_data(mp4) + (size_t) atom_data_size > mp4->buffer_end)
     {
         ngx_log_error(NGX_LOG_ERR, mp4->file.log, 0,
                       "\"%s\" mp4 ftyp atom is too large:%uL",
@@ -1304,7 +1308,7 @@
 
     trak->out[NGX_HTTP_MP4_TRAK_ATOM].buf = atom;
 
-    atom_end = mp4->buffer_pos + atom_data_size;
+    atom_end = mp4->buffer_pos + (size_t) atom_data_size;
     atom_file_end = mp4->offset + atom_data_size;
 
     rc = ngx_http_mp4_read_atom(mp4, ngx_http_mp4_trak_atoms, atom_data_size);
--- a/src/http/modules/ngx_http_proxy_module.c	Wed Sep 04 20:48:22 2013 +0400
+++ b/src/http/modules/ngx_http_proxy_module.c	Wed Sep 04 20:48:23 2013 +0400
@@ -1712,7 +1712,7 @@
 
             if (buf->last - buf->pos >= ctx->chunked.size) {
 
-                buf->pos += ctx->chunked.size;
+                buf->pos += (size_t) ctx->chunked.size;
                 b->last = buf->pos;
                 ctx->chunked.size = 0;
 
@@ -1875,7 +1875,7 @@
             b->tag = u->output.tag;
 
             if (buf->last - buf->pos >= ctx->chunked.size) {
-                buf->pos += ctx->chunked.size;
+                buf->pos += (size_t) ctx->chunked.size;
                 b->last = buf->pos;
                 ctx->chunked.size = 0;
 
--- a/src/http/modules/ngx_http_upstream_ip_hash_module.c	Wed Sep 04 20:48:22 2013 +0400
+++ b/src/http/modules/ngx_http_upstream_ip_hash_module.c	Wed Sep 04 20:48:23 2013 +0400
@@ -174,7 +174,7 @@
 
     for ( ;; ) {
 
-        for (i = 0; i < iphp->addrlen; i++) {
+        for (i = 0; i < (ngx_uint_t) iphp->addrlen; i++) {
             hash = (hash * 113 + iphp->addr[i]) % 6271;
         }
 
--- a/src/http/ngx_http_file_cache.c	Wed Sep 04 20:48:22 2013 +0400
+++ b/src/http/ngx_http_file_cache.c	Wed Sep 04 20:48:23 2013 +0400
@@ -503,7 +503,7 @@
         return NGX_DECLINED;
     }
 
-    if (h->body_start > c->body_start) {
+    if ((size_t) h->body_start > c->body_start) {
         ngx_log_error(NGX_LOG_CRIT, r->connection->log, 0,
                       "cache file \"%s\" has too long header",
                       c->file.name.data);
--- a/src/http/ngx_http_request_body.c	Wed Sep 04 20:48:22 2013 +0400
+++ b/src/http/ngx_http_request_body.c	Wed Sep 04 20:48:23 2013 +0400
@@ -714,7 +714,7 @@
                 size = b->last - b->pos;
 
                 if ((off_t) size > rb->chunked->size) {
-                    b->pos += rb->chunked->size;
+                    b->pos += (size_t) rb->chunked->size;
                     rb->chunked->size = 0;
 
                 } else {
@@ -753,7 +753,7 @@
         size = b->last - b->pos;
 
         if ((off_t) size > r->headers_in.content_length_n) {
-            b->pos += r->headers_in.content_length_n;
+            b->pos += (size_t) r->headers_in.content_length_n;
             r->headers_in.content_length_n = 0;
 
         } else {
@@ -866,7 +866,7 @@
             rb->rest -= size;
 
         } else {
-            cl->buf->pos += rb->rest;
+            cl->buf->pos += (size_t) rb->rest;
             rb->rest = 0;
             b->last = cl->buf->pos;
             b->last_buf = 1;
@@ -972,7 +972,7 @@
                 size = cl->buf->last - cl->buf->pos;
 
                 if ((off_t) size > rb->chunked->size) {
-                    cl->buf->pos += rb->chunked->size;
+                    cl->buf->pos += (size_t) rb->chunked->size;
                     r->headers_in.content_length_n += rb->chunked->size;
                     rb->chunked->size = 0;
 
--- a/src/os/win32/ngx_win32_config.h	Wed Sep 04 20:48:22 2013 +0400
+++ b/src/os/win32/ngx_win32_config.h	Wed Sep 04 20:48:23 2013 +0400
@@ -146,6 +146,14 @@
 typedef int                 dev_t;
 typedef unsigned int        ino_t;
 
+#elif __BORLANDC__
+
+/* off_t is redefined by sys/types.h used by zlib.h */
+#define __TYPES_H
+
+typedef int                 dev_t;
+typedef unsigned int        ino_t;
+
 #endif