Skip to content

Commit a8e93d6

Browse files
committed
patch 8.0.1127: Test_peek_and_get_char fails on 32 bit system
Problem: Test_peek_and_get_char fails on 32 bit system. (Eliminate Riesebieter) Solution: Avoid an integer overflow. (James McCoy, closes #2116)
1 parent 71b2964 commit a8e93d6

2 files changed

Lines changed: 23 additions & 24 deletions

File tree

src/ex_cmds2.c

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1090,15 +1090,24 @@ profile_zero(proftime_T *tm)
10901090
static timer_T *first_timer = NULL;
10911091
static long last_timer_id = 0;
10921092

1093-
# ifdef WIN3264
1094-
# define GET_TIMEDIFF(timer, now) \
1095-
(long)(((double)(timer->tr_due.QuadPart - now.QuadPart) \
1096-
/ (double)fr.QuadPart) * 1000)
1097-
# else
1098-
# define GET_TIMEDIFF(timer, now) \
1099-
(timer->tr_due.tv_sec - now.tv_sec) * 1000 \
1100-
+ (timer->tr_due.tv_usec - now.tv_usec) / 1000
1101-
# endif
1093+
static long
1094+
timer_time_left(timer_T *timer, proftime_T *now)
1095+
{
1096+
# ifdef WIN3264
1097+
LARGE_INTEGER fr;
1098+
1099+
if (now->QuadPart > timer->tr_due.QuadPart)
1100+
return 0;
1101+
QueryPerformanceFrequency(&fr);
1102+
return (long)(((double)(timer->tr_due.QuadPart - now->QuadPart)
1103+
/ (double)fr.QuadPart) * 1000);
1104+
# else
1105+
if (now->tv_sec > timer->tr_due.tv_sec)
1106+
return 0;
1107+
return (timer->tr_due.tv_sec - now->tv_sec) * 1000
1108+
+ (timer->tr_due.tv_usec - now->tv_usec) / 1000;
1109+
# endif
1110+
}
11021111

11031112
/*
11041113
* Insert a timer in the list of timers.
@@ -1196,25 +1205,19 @@ check_due_timer(void)
11961205
int did_one = FALSE;
11971206
int need_update_screen = FALSE;
11981207
long current_id = last_timer_id;
1199-
# ifdef WIN3264
1200-
LARGE_INTEGER fr;
1201-
# endif
12021208

12031209
/* Don't run any timers while exiting or dealing with an error. */
12041210
if (exiting || aborting())
12051211
return next_due;
12061212

1207-
# ifdef WIN3264
1208-
QueryPerformanceFrequency(&fr);
1209-
# endif
12101213
profile_start(&now);
12111214
for (timer = first_timer; timer != NULL && !got_int; timer = timer_next)
12121215
{
12131216
timer_next = timer->tr_next;
12141217

12151218
if (timer->tr_id == -1 || timer->tr_firing || timer->tr_paused)
12161219
continue;
1217-
this_due = GET_TIMEDIFF(timer, now);
1220+
this_due = timer_time_left(timer, &now);
12181221
if (this_due <= 1)
12191222
{
12201223
int save_timer_busy = timer_busy;
@@ -1266,7 +1269,7 @@ check_due_timer(void)
12661269
&& timer->tr_emsg_count < 3)
12671270
{
12681271
profile_setlimit(timer->tr_interval, &timer->tr_due);
1269-
this_due = GET_TIMEDIFF(timer, now);
1272+
this_due = timer_time_left(timer, &now);
12701273
if (this_due < 1)
12711274
this_due = 1;
12721275
if (timer->tr_repeat > 0)
@@ -1344,9 +1347,6 @@ add_timer_info(typval_T *rettv, timer_T *timer)
13441347
dictitem_T *di;
13451348
long remaining;
13461349
proftime_T now;
1347-
# ifdef WIN3264
1348-
LARGE_INTEGER fr;
1349-
#endif
13501350

13511351
if (dict == NULL)
13521352
return;
@@ -1356,10 +1356,7 @@ add_timer_info(typval_T *rettv, timer_T *timer)
13561356
dict_add_nr_str(dict, "time", (long)timer->tr_interval, NULL);
13571357

13581358
profile_start(&now);
1359-
# ifdef WIN3264
1360-
QueryPerformanceFrequency(&fr);
1361-
# endif
1362-
remaining = GET_TIMEDIFF(timer, now);
1359+
remaining = timer_time_left(timer, &now);
13631360
dict_add_nr_str(dict, "remaining", (long)remaining, NULL);
13641361

13651362
dict_add_nr_str(dict, "repeat",

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ static char *(features[]) =
761761

762762
static int included_patches[] =
763763
{ /* Add new patch number below this line */
764+
/**/
765+
1127,
764766
/**/
765767
1126,
766768
/**/

0 commit comments

Comments
 (0)