Clean up the argv splitter, and in particular stop it from bombing
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Wed, 7 Aug 2002 17:29:28 +0000 (17:29 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Wed, 7 Aug 2002 17:29:28 +0000 (17:29 +0000)
out ignominiously when given no arguments :-)

git-svn-id: svn://svn.tartarus.org/sgt/putty@1815 cda61777-01e9-0310-a592-d414129be87e

winutils.c

index 9d707ff..00d35df 100644 (file)
@@ -11,6 +11,8 @@
 #ifdef TESTMODE
 /* Definitions to allow this module to be compiled standalone for testing. */
 #define smalloc malloc
+#define srealloc realloc
+#define sfree free
 #endif
 
 /*
@@ -131,6 +133,18 @@ void split_into_argv(char *cmdline, int *argc, char ***argv,
      */
 
     /*
+     * First deal with the simplest of all special cases: if there
+     * aren't any arguments, return 0,NULL,NULL.
+     */
+    while (*cmdline && isspace(*cmdline)) cmdline++;
+    if (!*cmdline) {
+       if (argc) *argc = 0;
+       if (argv) *argv = NULL;
+       if (argstart) *argstart = NULL;
+       return;
+    }
+
+    /*
      * This will guaranteeably be big enough; we can realloc it
      * down later.
      */
@@ -446,4 +460,4 @@ int main(int argc, char **argv)
     return 0;
 }
 
-#endif
\ No newline at end of file
+#endif