[vlc-devel] [PATCH] winvlc: don't NULL terminate the libvlc_new() argv array

Rafaël Carré rafael.carre at gmail.com
Fri Oct 22 18:18:14 CEST 2010


---
 bin/winvlc.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/bin/winvlc.c b/bin/winvlc.c
index 1b9f475..f2cb167 100644
--- a/bin/winvlc.c
+++ b/bin/winvlc.c
@@ -77,13 +77,13 @@ static int parse_cmdline (char *line, char ***argvp)
             break;
 
         /* Starts a new parameter */
-        argv = realloc (argv, (argc + 2) * sizeof (char *));
+        argv = realloc (argv, ++argc * sizeof (char *));
         if (*line == '"')
         {
             quote = '"';
             line++;
         }
-        argv[argc++] = line;
+        argv[argc - 1] = line;
 
     more:
             while (*line && !strchr ("\t ", *line))
@@ -104,7 +104,7 @@ static int parse_cmdline (char *line, char ***argvp)
         if (*line)
             *line++ = 0;
     }
-    argv[argc] = NULL;
+
     *argvp = argv;
     return argc;
 }
@@ -139,13 +139,14 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
     if (wargv == NULL)
         return 1;
 
-    char *argv[argc + 2];
+    const int skip = 1; /* argv[0] */
+    char *argv[argc + 2 - skip];
     BOOL crash_handling = TRUE;
     int j = 0;
 
     argv[j++] = FromWide( L"--media-library" );
     argv[j++] = FromWide( L"--no-ignore-config" );
-    for (int i = 1; i < argc; i++)
+    for (int i = skip; i < argc; i++)
     {
         if(!wcscmp(wargv[i], L"--no-crashdump"))
         {
@@ -157,7 +158,6 @@ int WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance,
     }
 
     argc = j;
-    argv[argc] = NULL;
     LocalFree (wargv);
 
 # ifndef _WIN64
-- 
1.7.3.2





More information about the vlc-devel mailing list