[PATCH 02 of 15] ngx core - ensure that tempfile number never be 0

Jiří Setnička jiri.setnicka at cdn77.com
Fri Jan 28 16:31:54 UTC 2022


# HG changeset patch
# User Jiří Setnička  <jiri.setnicka at cdn77.com>
# Date 1643385660 -3600
#      Fri Jan 28 17:01:00 2022 +0100
# Node ID 64ff9068a0bd89712a0ae6fc589a881869663642
# Parent  ca39d3040e2a9c37eb0940c5880fead78d5d137c
ngx core - ensure that tempfile number never be 0
To be able to use 0 as special value meaning "no tempfile".

diff --git a/src/core/ngx_file.c b/src/core/ngx_file.c
--- a/src/core/ngx_file.c
+++ b/src/core/ngx_file.c
@@ -365,7 +365,9 @@ ngx_next_temp_number(ngx_uint_t collisio
 
     add = collision ? ngx_random_number : 1;
 
-    n = ngx_atomic_fetch_add(ngx_temp_number, add);
+    do {
+        n = ngx_atomic_fetch_add(ngx_temp_number, add);
+    } while (n + add == 0);
 
     return n + add;
 }


More information about the nginx-devel mailing list