]> asedeno.scripts.mit.edu Git - PuTTY.git/commitdiff
Clean up the argv splitter, and in particular stop it from bombing
authorSimon Tatham <anakin@pobox.com>
Wed, 7 Aug 2002 17:29:28 +0000 (17:29 +0000)
committerSimon Tatham <anakin@pobox.com>
Wed, 7 Aug 2002 17:29:28 +0000 (17:29 +0000)
out ignominiously when given no arguments :-)

[originally from svn r1815]

winutils.c

index 9d707ff1e60626cde1e80cc5bcccca7ab4d3914b..00d35dfbded07abf2d46fa70c8b11d83fcadac0d 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
 
 /*
@@ -130,6 +132,18 @@ void split_into_argv(char *cmdline, int *argc, char ***argv,
      *    produce a literal quote.
      */
 
+    /*
+     * 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