changeset 4582:a8881886a5f7

Improved readability of the code that produces bitmask from prefix. In collaboration with Maxim Dounin.
author Ruslan Ermilov <ru@nginx.com>
date Wed, 11 Apr 2012 17:18:15 +0000
parents f84a98a03d0d
children a1d5842064f7
files src/core/ngx_inet.c
diffstat 1 files changed, 2 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/core/ngx_inet.c
+++ b/src/core/ngx_inet.c
@@ -420,7 +420,7 @@ ngx_ptocidr(ngx_str_t *text, ngx_cidr_t 
             s = (shift > 8) ? 8 : shift;
             shift -= s;
 
-            mask[i] = (u_char) (0 - (1 << (8 - s)));
+            mask[i] = (u_char) (0xffu << (8 - s));
 
             if (addr[i] != (addr[i] & mask[i])) {
                 rc = NGX_DONE;
@@ -437,7 +437,7 @@ ngx_ptocidr(ngx_str_t *text, ngx_cidr_t 
         }
 
         if (shift) {
-            cidr->u.in.mask = htonl((ngx_uint_t) (0 - (1 << (32 - shift))));
+            cidr->u.in.mask = htonl((uint32_t) (0xffffffffu << (32 - shift)));
 
         } else {
             /* x86 compilers use a shl instruction that shifts by modulo 32 */