Improved readability of the code that produces bitmask from prefix.
In collaboration with Maxim Dounin.
Ruslan Ermilov
10 years ago
419 | 419 | s = (shift > 8) ? 8 : shift; |
420 | 420 | shift -= s; |
421 | 421 | |
422 | mask[i] = (u_char) (0 - (1 << (8 - s))); | |
422 | mask[i] = (u_char) (0xffu << (8 - s)); | |
423 | 423 | |
424 | 424 | if (addr[i] != (addr[i] & mask[i])) { |
425 | 425 | rc = NGX_DONE; |
436 | 436 | } |
437 | 437 | |
438 | 438 | if (shift) { |
439 | cidr->u.in.mask = htonl((ngx_uint_t) (0 - (1 << (32 - shift)))); | |
439 | cidr->u.in.mask = htonl((uint32_t) (0xffffffffu << (32 - shift))); | |
440 | 440 | |
441 | 441 | } else { |
442 | 442 | /* x86 compilers use a shl instruction that shifts by modulo 32 */ |