[MPlayer-cvslog] r33059 - trunk/gui/mplayer/gui_common.c

ib subversion at mplayerhq.hu
Tue Mar 8 21:56:51 CET 2011


Author: ib
Date: Tue Mar  8 21:56:51 2011
New Revision: 33059

Log:
Fix several issues with Translate().

1. The "Unsafe!" comment has been removed, because the strings passed
   to the function are strcpy'd.

2. The needless memsets (one of which with wrong size) have been removed
   in favor of a sufficiently simple initialization of trbuf.

3. The array indices are unsigned now, and the manual optimization of
   having strlen() outside the for loop has been removed in favor of
   optimization performed by the compiler.

4. There is a check now to prevent an out-of-bounds array access.

Modified:
   trunk/gui/mplayer/gui_common.c

Modified: trunk/gui/mplayer/gui_common.c
==============================================================================
--- trunk/gui/mplayer/gui_common.c	Tue Mar  8 20:07:55 2011	(r33058)
+++ trunk/gui/mplayer/gui_common.c	Tue Mar  8 21:56:51 2011	(r33059)
@@ -107,24 +107,22 @@ static void TranslateFilename(int c, cha
     }
 }
 
-/* Unsafe!  Pass only null-terminated strings as (char *)str. */
 char *Translate(char *str)
 {
     static char trbuf[512];
     char tmp[512];
-    int i, c;
+    unsigned int i, c;
     int t;
-    int strsize = 0;
     mixer_t *mixer;
 
-    memset(trbuf, 0, 512);
-    memset(tmp, 0, 128);
-    strsize = strlen(str);
+    *trbuf = 0;
 
-    for (c = 0, i = 0; i < strsize; i++) {
+    for (c = 0, i = 0; i < strlen(str); i++) {
         if (str[i] != '$') {
+            if (c + 1 < sizeof(trbuf)) {
             trbuf[c++] = str[i];
             trbuf[c]   = 0;
+            }
         } else {
             switch (str[++i]) {
             case 't':


More information about the MPlayer-cvslog mailing list