[MPlayer-users] fix for mplayer input bugs: shooting to memory+lost events

Mikulas Patocka mikulas at artax.karlin.mff.cuni.cz
Wed Jun 30 02:42:03 CEST 2004


Hi

This patch fixes two problems in mplayer input key system:

1. shooting to stack when only partial data are read from pipe (note that
when adding number to pointer, the number is multiplied by size of pointer
type).

2. delayed events on svgalib:

The problem is caused by getch2, getch2 does buffering of handle 0,
however getch2 is called only when handle 0 is reported as readable by
select.

It manifests like this:
- User holds key so that key repeat rate is higher than frame rate
	(key presses are put into buffer in getch2)
- User releases key
	(handle 0 is no longer reported as readable, however there are
	 still charactes in getch2 buffer, but getch2 is not called
	 anymore)
- User presses another key --- few keypresses of previous key are still
processed.
	(getch2 is called and previous content of getch2 buffer is
	 processed)

The patch changes it so that getch2 is always called regardless of select
state of handle 0 --- it makes sense because getch2 calls select itself.

Mikulas

--- input/input.c_	2004-06-30 02:04:43.000000000 +0100
+++ input/input.c	2004-06-30 02:25:50.000000000 +0100
@@ -656,7 +656,7 @@
   unsigned int l;
   l = 0;
   while(l < sizeof(int)) {
-    r = read(fd,(&code)+l,sizeof(int)-l);
+    r = read(fd,((char *)&code)+l,sizeof(int)-l);
     if(r <= 0)
       break;
     l +=r;
@@ -902,7 +902,7 @@
     }
 #ifndef HAVE_NO_POSIX_SELECT
     // No input from this fd
-    if(! (key_fds[i].flags & MP_FD_NO_SELECT) && ! FD_ISSET(key_fds[i].fd,&fds))
+    if(! (key_fds[i].flags & MP_FD_NO_SELECT) && ! FD_ISSET(key_fds[i].fd,&fds) && key_fds[i].fd != 0)
       continue;
 #endif
     if(key_fds[i].fd == 0) { // stdin is handled by getch2




More information about the MPlayer-users mailing list