X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=winutils.c;h=d55e890144404734f72c9dbcd0cd79bd15b13083;hb=6b362191f1a2c6897e7b7bfa80beec1cd1f722fd;hp=9d707ff1e60626cde1e80cc5bcccca7ab4d3914b;hpb=437d740fb32b6cf2b8c3df853265b8202f2ca407;p=PuTTY.git diff --git a/winutils.c b/winutils.c index 9d707ff1..d55e8901 100644 --- a/winutils.c +++ b/winutils.c @@ -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,13 +132,25 @@ 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. */ - outputline = smalloc(1+strlen(cmdline)); - outputargv = smalloc(sizeof(char *) * (strlen(cmdline)+1 / 2)); - outputargstart = smalloc(sizeof(char *) * (strlen(cmdline)+1 / 2)); + outputline = snewn(1+strlen(cmdline), char); + outputargv = snewn(strlen(cmdline)+1 / 2, char *); + outputargstart = snewn(strlen(cmdline)+1 / 2, char *); p = cmdline; q = outputline; outputargc = 0; @@ -203,8 +217,8 @@ void split_into_argv(char *cmdline, int *argc, char ***argv, *q++ = '\0'; } - outputargv = srealloc(outputargv, sizeof(char *) * outputargc); - outputargstart = srealloc(outputargstart, sizeof(char *) * outputargc); + outputargv = sresize(outputargv, outputargc, char *); + outputargstart = sresize(outputargstart, outputargc, char *); if (argc) *argc = outputargc; if (argv) *argv = outputargv; else sfree(outputargv); @@ -446,4 +460,4 @@ int main(int argc, char **argv) return 0; } -#endif \ No newline at end of file +#endif