Skip to content

Commit e23eb34

Browse files
committed
Fixed possible overflow issue with use of PDC_millisecs().
This function returns a long. If that's 32 bits, it will wrap every 49.7 days. It should be treated as a relative measurement between two times. In some of the code handling mouse events, this wasn't the case, and a precisely-timed mouse press could cause a program to wait 49.7 days for the release.
1 parent 10791c9 commit e23eb34

3 files changed

Lines changed: 12 additions & 9 deletions

File tree

fb/pdckbd.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,13 @@ static void _check_mouse( void)
5656
const int yper = ((PDC_orientation & 1) ? PDC_font_info.width : PDC_font_info.height);
5757
const int xmax = SP->cols * xper;
5858
const int ymax = SP->lines * yper;
59-
long timeout = 0;
59+
long prev_t = 0;
6060

6161
_key_modifiers = PDC_get_modifiers( );
6262
if( _get_mouse_event( NULL)) /* already got events queued up */
6363
return;
64-
while( (event = PDC_update_mouse( &button)) >= 0 || PDC_millisecs() < timeout)
64+
while( (event = PDC_update_mouse( &button)) >= 0 ||
65+
(prev_t && PDC_millisecs() - prev_t < SP->mouse_wait))
6566
{
6667
int x, y;
6768

@@ -88,13 +89,14 @@ static void _check_mouse( void)
8889
}
8990
else if( event == BUTTON_PRESSED || event == BUTTON_RELEASED)
9091
{
91-
if( _add_raw_mouse_event( button - 1, event, modifs, x, y))
92-
timeout = PDC_millisecs( ) + SP->mouse_wait;
92+
if( _add_raw_mouse_event( button - 1, event, modifs, x, y)
93+
&& SP->mouse_wait)
94+
prev_t = PDC_millisecs( );
9395
else
9496
break;
9597
}
9698
}
97-
else if( timeout)
99+
else if( prev_t)
98100
napms( 10);
99101
}
100102
if( mx != PDC_mouse_x || my != PDC_mouse_y)

vt/pdckbd.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,9 +433,10 @@ int PDC_get_key( void)
433433
while( more_mouse)
434434
{
435435
const long t_end = PDC_millisecs( ) + SP->mouse_wait;
436+
long t;
436437

437-
while( !check_key( NULL) && PDC_millisecs( ) < t_end)
438-
PDC_napms( 20);
438+
while( !check_key( NULL) && (t = t_end - PDC_millisecs( )) > 0)
439+
PDC_napms( t < 20 ? (int)t : 20);
439440
more_mouse = (check_key( NULL) && PDC_get_key( ) == KEY_MOUSE);
440441
}
441442
recursed = FALSE;

x11new/pdckbd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -640,8 +640,8 @@ static bool check_key( int *c)
640640
const long t_end = PDC_millisecs( ) + SP->mouse_wait;
641641
long t;
642642

643-
while( (t = PDC_millisecs( )) < t_end && !XPending( dis))
644-
napms( t_end - t < 20L ? (int)( t_end - t) : 20);
643+
while( (t = t_end - PDC_millisecs( )) > 0 && !XPending( dis))
644+
napms( t < 20L ? (int)t : 20);
645645
}
646646
if( !XPending( dis) || (!wait_for_more_mouse && _mlist_count))
647647
{

0 commit comments

Comments
 (0)