comparison src/core/ngx_rbtree.c @ 4576:876e6b0814a5

Fixed signed integer overflows in timer code (ticket #145). Integer overflow is undefined behaviour in C and this indeed caused problems on Solaris/SPARC (at least in some cases). Fix is to subtract unsigned integers instead, and then cast result to a signed one, which is implementation-defined behaviour and used to work. Strictly speaking, we should compare (unsigned) result with the maximum value of the corresponding signed integer type instead, this will be defined behaviour. This will require much more changes though, and considered to be overkill for now.
author Maxim Dounin <mdounin@mdounin.ru>
date Fri, 06 Apr 2012 23:46:09 +0000
parents d620f497c50f
children 1f513d7f1b45
comparison
equal deleted inserted replaced
4575:709d7d24239d 4576:876e6b0814a5
134 * The comparison takes into account that overflow. 134 * The comparison takes into account that overflow.
135 */ 135 */
136 136
137 /* node->key < temp->key */ 137 /* node->key < temp->key */
138 138
139 p = ((ngx_rbtree_key_int_t) node->key - (ngx_rbtree_key_int_t) temp->key 139 p = ((ngx_rbtree_key_int_t) (node->key - temp->key) < 0)
140 < 0)
141 ? &temp->left : &temp->right; 140 ? &temp->left : &temp->right;
142 141
143 if (*p == sentinel) { 142 if (*p == sentinel) {
144 break; 143 break;
145 } 144 }