[PATCH] GeoIP: rearranged checks to avoid dead code

Maxim Dounin mdounin at mdounin.ru
Mon Dec 15 00:32:32 UTC 2025


# HG changeset patch
# User Maxim Dounin <mdounin at mdounin.ru>
# Date 1765750562 -10800
#      Mon Dec 15 01:16:02 2025 +0300
# Node ID b401e3f56bdadb60efc0f51e1a195958d52254c8
# Parent  f5ce4ebcec7e85d43a170b07b79a446798e24f83
GeoIP: rearranged checks to avoid dead code.

The "ngx_http_geoip_mmdb_file() == NGX_OK" checks are not executed when
both the legacy GeoIP library and libmaxminddb available, and Coverity
complains that the code is dead.  Fix is to rearrange to code so the
checks are not compiled at all if both libraries are available.

Prodded by Coverity.

diff --git a/src/http/modules/ngx_http_geoip_module.c b/src/http/modules/ngx_http_geoip_module.c
--- a/src/http/modules/ngx_http_geoip_module.c
+++ b/src/http/modules/ngx_http_geoip_module.c
@@ -1112,14 +1112,16 @@ ngx_http_geoip_country(ngx_conf_t *cf, n
 
 #if (NGX_HAVE_GEOIP_LEGACY)
 
+#if (NGX_HAVE_GEOIP_MMDB)
+
+legacy:
+
+#else
+
     if (ngx_http_geoip_mmdb_file(&value[1]) == NGX_OK) {
         return "does not support mmdb databases on this platform";
     }
 
-#if (NGX_HAVE_GEOIP_MMDB)
-
-legacy:
-
 #endif
 
     gcf->country = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE);
@@ -1213,14 +1215,16 @@ ngx_http_geoip_org(ngx_conf_t *cf, ngx_c
 
 #if (NGX_HAVE_GEOIP_LEGACY)
 
+#if (NGX_HAVE_GEOIP_MMDB)
+
+legacy:
+
+#else
+
     if (ngx_http_geoip_mmdb_file(&value[1]) == NGX_OK) {
         return "does not support mmdb databases on this platform";
     }
 
-#if (NGX_HAVE_GEOIP_MMDB)
-
-legacy:
-
 #endif
 
     gcf->org = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE);
@@ -1320,14 +1324,16 @@ ngx_http_geoip_city(ngx_conf_t *cf, ngx_
 
 #if (NGX_HAVE_GEOIP_LEGACY)
 
+#if (NGX_HAVE_GEOIP_MMDB)
+
+legacy:
+
+#else
+
     if (ngx_http_geoip_mmdb_file(&value[1]) == NGX_OK) {
         return "does not support mmdb databases on this platform";
     }
 
-#if (NGX_HAVE_GEOIP_MMDB)
-
-legacy:
-
 #endif
 
     gcf->city = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE);
diff --git a/src/stream/ngx_stream_geoip_module.c b/src/stream/ngx_stream_geoip_module.c
--- a/src/stream/ngx_stream_geoip_module.c
+++ b/src/stream/ngx_stream_geoip_module.c
@@ -1049,14 +1049,16 @@ ngx_stream_geoip_country(ngx_conf_t *cf,
 
 #if (NGX_HAVE_GEOIP_LEGACY)
 
+#if (NGX_HAVE_GEOIP_MMDB)
+
+legacy:
+
+#else
+
     if (ngx_stream_geoip_mmdb_file(&value[1]) == NGX_OK) {
         return "does not support mmdb databases on this platform";
     }
 
-#if (NGX_HAVE_GEOIP_MMDB)
-
-legacy:
-
 #endif
 
     gcf->country = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE);
@@ -1150,14 +1152,16 @@ ngx_stream_geoip_org(ngx_conf_t *cf, ngx
 
 #if (NGX_HAVE_GEOIP_LEGACY)
 
+#if (NGX_HAVE_GEOIP_MMDB)
+
+legacy:
+
+#else
+
     if (ngx_stream_geoip_mmdb_file(&value[1]) == NGX_OK) {
         return "does not support mmdb databases on this platform";
     }
 
-#if (NGX_HAVE_GEOIP_MMDB)
-
-legacy:
-
 #endif
 
     gcf->org = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE);
@@ -1257,14 +1261,16 @@ ngx_stream_geoip_city(ngx_conf_t *cf, ng
 
 #if (NGX_HAVE_GEOIP_LEGACY)
 
+#if (NGX_HAVE_GEOIP_MMDB)
+
+legacy:
+
+#else
+
     if (ngx_stream_geoip_mmdb_file(&value[1]) == NGX_OK) {
         return "does not support mmdb databases on this platform";
     }
 
-#if (NGX_HAVE_GEOIP_MMDB)
-
-legacy:
-
 #endif
 
     gcf->city = GeoIP_open((char *) value[1].data, GEOIP_MEMORY_CACHE);



More information about the nginx-devel mailing list