Mercurial > vim
comparison src/os_unix.c @ 29191:0af5fe160e4e v8.2.5115
patch 8.2.5115: search timeout is overrun with some patterns
Commit: https://github.com/vim/vim/commit/616592e0816d2d9f893fcd95e3e1e0fbc5893168
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Jun 17 15:17:10 2022 +0100
patch 8.2.5115: search timeout is overrun with some patterns
Problem: Search timeout is overrun with some patterns.
Solution: Check for timeout in more places. Make the flag volatile and
atomic. Use assert_inrange() to see what happened.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 17 Jun 2022 16:30:06 +0200 |
parents | 87ad2de4fe41 |
children | d6f8b784d0f6 |
comparison
equal
deleted
inserted
replaced
29190:a4f0e5e61728 | 29191:0af5fe160e4e |
---|---|
8249 #if defined(FEAT_RELTIME) || defined(PROTO) | 8249 #if defined(FEAT_RELTIME) || defined(PROTO) |
8250 # if defined(HAVE_TIMER_CREATE) || defined(PROTO) | 8250 # if defined(HAVE_TIMER_CREATE) || defined(PROTO) |
8251 /* | 8251 /* |
8252 * Implement timeout with timer_create() and timer_settime(). | 8252 * Implement timeout with timer_create() and timer_settime(). |
8253 */ | 8253 */ |
8254 static int timeout_flag = FALSE; | 8254 static volatile int timeout_flag = FALSE; |
8255 static timer_t timer_id; | 8255 static timer_t timer_id; |
8256 static int timer_created = FALSE; | 8256 static int timer_created = FALSE; |
8257 | 8257 |
8258 /* | 8258 /* |
8259 * Callback for when the timer expires. | 8259 * Callback for when the timer expires. |
8294 * safely dereferenced. | 8294 * safely dereferenced. |
8295 * | 8295 * |
8296 * This function is not expected to fail, but if it does it will still return a | 8296 * This function is not expected to fail, but if it does it will still return a |
8297 * valid flag pointer; the flag will remain stuck as FALSE . | 8297 * valid flag pointer; the flag will remain stuck as FALSE . |
8298 */ | 8298 */ |
8299 const int * | 8299 volatile int * |
8300 start_timeout(long msec) | 8300 start_timeout(long msec) |
8301 { | 8301 { |
8302 struct itimerspec interval = { | 8302 struct itimerspec interval = { |
8303 {0, 0}, // Do not repeat. | 8303 {0, 0}, // Do not repeat. |
8304 {msec / 1000, (msec % 1000) * 1000000}}; // Timeout interval | 8304 {msec / 1000, (msec % 1000) * 1000000}}; // Timeout interval |
8322 return &timeout_flag; | 8322 return &timeout_flag; |
8323 } | 8323 } |
8324 timer_created = TRUE; | 8324 timer_created = TRUE; |
8325 } | 8325 } |
8326 | 8326 |
8327 ch_log(NULL, "setting timeout timer to %d sec %ld nsec", | |
8328 (int)interval.it_value.tv_sec, (long)interval.it_value.tv_nsec); | |
8327 ret = timer_settime(timer_id, 0, &interval, NULL); | 8329 ret = timer_settime(timer_id, 0, &interval, NULL); |
8328 if (ret < 0) | 8330 if (ret < 0) |
8329 semsg(_(e_could_not_set_timeout_str), strerror(errno)); | 8331 semsg(_(e_could_not_set_timeout_str), strerror(errno)); |
8330 | 8332 |
8331 return &timeout_flag; | 8333 return &timeout_flag; |
8349 /* | 8351 /* |
8350 * Implement timeout with setitimer() | 8352 * Implement timeout with setitimer() |
8351 */ | 8353 */ |
8352 static struct itimerval prev_interval; | 8354 static struct itimerval prev_interval; |
8353 static struct sigaction prev_sigaction; | 8355 static struct sigaction prev_sigaction; |
8354 static int timeout_flag = FALSE; | 8356 static volatile int timeout_flag = FALSE; |
8355 static int timer_active = FALSE; | 8357 static int timer_active = FALSE; |
8356 static int timer_handler_active = FALSE; | 8358 static int timer_handler_active = FALSE; |
8357 static int alarm_pending = FALSE; | 8359 static int alarm_pending = FALSE; |
8358 | 8360 |
8359 /* | 8361 /* |
8407 * safely dereferenced. | 8409 * safely dereferenced. |
8408 * | 8410 * |
8409 * This function is not expected to fail, but if it does it will still return a | 8411 * This function is not expected to fail, but if it does it will still return a |
8410 * valid flag pointer; the flag will remain stuck as FALSE . | 8412 * valid flag pointer; the flag will remain stuck as FALSE . |
8411 */ | 8413 */ |
8412 const int * | 8414 volatile int * |
8413 start_timeout(long msec) | 8415 start_timeout(long msec) |
8414 { | 8416 { |
8415 struct itimerval interval = { | 8417 struct itimerval interval = { |
8416 {0, 0}, // Do not repeat. | 8418 {0, 0}, // Do not repeat. |
8417 {msec / 1000, (msec % 1000) * 1000}}; // Timeout interval | 8419 {msec / 1000, (msec % 1000) * 1000}}; // Timeout interval |