diff options
author | Maxim Dounin <mdounin@mdounin.ru> | 2012-04-07 03:46:09 +0400 |
---|---|---|
committer | Maxim Dounin <mdounin@mdounin.ru> | 2012-04-07 03:46:09 +0400 |
commit | baa239c4870ba2236aeb8c54b892dd25d43d780a (patch) | |
tree | 17e1e5b2c97e57cfd012e9b14109916cd419d17b /src/core/ngx_rbtree.c | |
parent | bd6d421816f6e317eec512620a51aa0521288405 (diff) |
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.
Diffstat (limited to 'src/core/ngx_rbtree.c')
-rw-r--r-- | src/core/ngx_rbtree.c | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/src/core/ngx_rbtree.c b/src/core/ngx_rbtree.c index 6ae4d5c05..914ca7e88 100644 --- a/src/core/ngx_rbtree.c +++ b/src/core/ngx_rbtree.c @@ -136,8 +136,7 @@ ngx_rbtree_insert_timer_value(ngx_rbtree_node_t *temp, ngx_rbtree_node_t *node, /* node->key < temp->key */ - p = ((ngx_rbtree_key_int_t) node->key - (ngx_rbtree_key_int_t) temp->key - < 0) + p = ((ngx_rbtree_key_int_t) (node->key - temp->key) < 0) ? &temp->left : &temp->right; if (*p == sentinel) { |