Klaus Demo nginx / baa239c
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. Maxim Dounin 10 years ago
2 changed file(s) with 3 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
135135
136136 /* node->key < temp->key */
137137
138 p = ((ngx_rbtree_key_int_t) node->key - (ngx_rbtree_key_int_t) temp->key
139 < 0)
138 p = ((ngx_rbtree_key_int_t) (node->key - temp->key) < 0)
140139 ? &temp->left : &temp->right;
141140
142141 if (*p == sentinel) {
6666
6767 ngx_mutex_unlock(ngx_event_timer_mutex);
6868
69 timer = (ngx_msec_int_t) node->key - (ngx_msec_int_t) ngx_current_msec;
69 timer = (ngx_msec_int_t) (node->key - ngx_current_msec);
7070
7171 return (ngx_msec_t) (timer > 0 ? timer : 0);
7272 }
9494
9595 /* node->key <= ngx_current_time */
9696
97 if ((ngx_msec_int_t) node->key - (ngx_msec_int_t) ngx_current_msec <= 0)
98 {
97 if ((ngx_msec_int_t) (node->key - ngx_current_msec) <= 0) {
9998 ev = (ngx_event_t *) ((char *) node - offsetof(ngx_event_t, timer));
10099
101100 #if (NGX_THREADS)