Mercurial > vim
comparison src/ex_cmds2.c @ 12495:65f8c6fcfd83 v8.0.1127
patch 8.0.1127: Test_peek_and_get_char fails on 32 bit system
commit https://github.com/vim/vim/commit/a8e93d63e308020ee06eb5782e766941ac417a5a
Author: Bram Moolenaar <Bram@vim.org>
Date: Mon Sep 18 21:50:47 2017 +0200
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)
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Mon, 18 Sep 2017 22:00:04 +0200 |
parents | 68d7bc045dbe |
children | 20aacdca367d |
comparison
equal
deleted
inserted
replaced
12494:b08f916fec04 | 12495:65f8c6fcfd83 |
---|---|
1088 | 1088 |
1089 # if defined(FEAT_TIMERS) || defined(PROTO) | 1089 # if defined(FEAT_TIMERS) || defined(PROTO) |
1090 static timer_T *first_timer = NULL; | 1090 static timer_T *first_timer = NULL; |
1091 static long last_timer_id = 0; | 1091 static long last_timer_id = 0; |
1092 | 1092 |
1093 # ifdef WIN3264 | 1093 static long |
1094 # define GET_TIMEDIFF(timer, now) \ | 1094 timer_time_left(timer_T *timer, proftime_T *now) |
1095 (long)(((double)(timer->tr_due.QuadPart - now.QuadPart) \ | 1095 { |
1096 / (double)fr.QuadPart) * 1000) | 1096 # ifdef WIN3264 |
1097 # else | 1097 LARGE_INTEGER fr; |
1098 # define GET_TIMEDIFF(timer, now) \ | 1098 |
1099 (timer->tr_due.tv_sec - now.tv_sec) * 1000 \ | 1099 if (now->QuadPart > timer->tr_due.QuadPart) |
1100 + (timer->tr_due.tv_usec - now.tv_usec) / 1000 | 1100 return 0; |
1101 # endif | 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 } | |
1102 | 1111 |
1103 /* | 1112 /* |
1104 * Insert a timer in the list of timers. | 1113 * Insert a timer in the list of timers. |
1105 */ | 1114 */ |
1106 static void | 1115 static void |
1194 long next_due = -1; | 1203 long next_due = -1; |
1195 proftime_T now; | 1204 proftime_T now; |
1196 int did_one = FALSE; | 1205 int did_one = FALSE; |
1197 int need_update_screen = FALSE; | 1206 int need_update_screen = FALSE; |
1198 long current_id = last_timer_id; | 1207 long current_id = last_timer_id; |
1199 # ifdef WIN3264 | |
1200 LARGE_INTEGER fr; | |
1201 # endif | |
1202 | 1208 |
1203 /* Don't run any timers while exiting or dealing with an error. */ | 1209 /* Don't run any timers while exiting or dealing with an error. */ |
1204 if (exiting || aborting()) | 1210 if (exiting || aborting()) |
1205 return next_due; | 1211 return next_due; |
1206 | 1212 |
1207 # ifdef WIN3264 | |
1208 QueryPerformanceFrequency(&fr); | |
1209 # endif | |
1210 profile_start(&now); | 1213 profile_start(&now); |
1211 for (timer = first_timer; timer != NULL && !got_int; timer = timer_next) | 1214 for (timer = first_timer; timer != NULL && !got_int; timer = timer_next) |
1212 { | 1215 { |
1213 timer_next = timer->tr_next; | 1216 timer_next = timer->tr_next; |
1214 | 1217 |
1215 if (timer->tr_id == -1 || timer->tr_firing || timer->tr_paused) | 1218 if (timer->tr_id == -1 || timer->tr_firing || timer->tr_paused) |
1216 continue; | 1219 continue; |
1217 this_due = GET_TIMEDIFF(timer, now); | 1220 this_due = timer_time_left(timer, &now); |
1218 if (this_due <= 1) | 1221 if (this_due <= 1) |
1219 { | 1222 { |
1220 int save_timer_busy = timer_busy; | 1223 int save_timer_busy = timer_busy; |
1221 int save_vgetc_busy = vgetc_busy; | 1224 int save_vgetc_busy = vgetc_busy; |
1222 int save_did_emsg = did_emsg; | 1225 int save_did_emsg = did_emsg; |
1264 * called while inside the callback (tr_id == -1). */ | 1267 * called while inside the callback (tr_id == -1). */ |
1265 if (timer->tr_repeat != 0 && timer->tr_id != -1 | 1268 if (timer->tr_repeat != 0 && timer->tr_id != -1 |
1266 && timer->tr_emsg_count < 3) | 1269 && timer->tr_emsg_count < 3) |
1267 { | 1270 { |
1268 profile_setlimit(timer->tr_interval, &timer->tr_due); | 1271 profile_setlimit(timer->tr_interval, &timer->tr_due); |
1269 this_due = GET_TIMEDIFF(timer, now); | 1272 this_due = timer_time_left(timer, &now); |
1270 if (this_due < 1) | 1273 if (this_due < 1) |
1271 this_due = 1; | 1274 this_due = 1; |
1272 if (timer->tr_repeat > 0) | 1275 if (timer->tr_repeat > 0) |
1273 --timer->tr_repeat; | 1276 --timer->tr_repeat; |
1274 } | 1277 } |
1342 list_T *list = rettv->vval.v_list; | 1345 list_T *list = rettv->vval.v_list; |
1343 dict_T *dict = dict_alloc(); | 1346 dict_T *dict = dict_alloc(); |
1344 dictitem_T *di; | 1347 dictitem_T *di; |
1345 long remaining; | 1348 long remaining; |
1346 proftime_T now; | 1349 proftime_T now; |
1347 # ifdef WIN3264 | |
1348 LARGE_INTEGER fr; | |
1349 #endif | |
1350 | 1350 |
1351 if (dict == NULL) | 1351 if (dict == NULL) |
1352 return; | 1352 return; |
1353 list_append_dict(list, dict); | 1353 list_append_dict(list, dict); |
1354 | 1354 |
1355 dict_add_nr_str(dict, "id", timer->tr_id, NULL); | 1355 dict_add_nr_str(dict, "id", timer->tr_id, NULL); |
1356 dict_add_nr_str(dict, "time", (long)timer->tr_interval, NULL); | 1356 dict_add_nr_str(dict, "time", (long)timer->tr_interval, NULL); |
1357 | 1357 |
1358 profile_start(&now); | 1358 profile_start(&now); |
1359 # ifdef WIN3264 | 1359 remaining = timer_time_left(timer, &now); |
1360 QueryPerformanceFrequency(&fr); | |
1361 # endif | |
1362 remaining = GET_TIMEDIFF(timer, now); | |
1363 dict_add_nr_str(dict, "remaining", (long)remaining, NULL); | 1360 dict_add_nr_str(dict, "remaining", (long)remaining, NULL); |
1364 | 1361 |
1365 dict_add_nr_str(dict, "repeat", | 1362 dict_add_nr_str(dict, "repeat", |
1366 (long)(timer->tr_repeat < 0 ? -1 : timer->tr_repeat + 1), NULL); | 1363 (long)(timer->tr_repeat < 0 ? -1 : timer->tr_repeat + 1), NULL); |
1367 dict_add_nr_str(dict, "paused", (long)(timer->tr_paused), NULL); | 1364 dict_add_nr_str(dict, "paused", (long)(timer->tr_paused), NULL); |