Fix off by one bugs
authorRémi Denis-Courmont <rem@videolan.org>
Sat, 4 Mar 2006 22:05:10 +0000 (22:05 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Sat, 4 Mar 2006 22:05:10 +0000 (22:05 +0000)
modules/gui/wxwidgets/interface.cpp

index 6e628df..65e9576 100644 (file)
@@ -1278,17 +1278,17 @@ bool DragAndDrop::OnDropFiles( wxCoord, wxCoord,
          * UTF-8 but also Windows-1252(!) and ISO-8859-15(!) or any
          * non-western encoding, it obviously fails.
          */
-        unsigned len = 1;
         const wxChar *stupid = filenames[i];
 
-        for (const wxChar *braindead = stupid; *braindead; braindead++)
-            len++;
-        char *psz_local = (char *)malloc (len);
+        for (const wxChar *braindead = stupid; *braindead; braindead++);
+
+        size_t i = (braindead - stupid);
+        char *psz_local = (char *)malloc( i + 1 );
         do
-            psz_local[len] = (char)stupid[len];
-        while (len--);
+            psz_local[i] = (char)stupid[i];
+        while (i--);
 
-        char *psz_utf8 = FromLocale( psz_local );
+        const char *psz_utf8 = FromLocale( psz_local );
 #else
         char *psz_utf8 = wxFromLocale( filenames[i] );
 #endif