Merge branch 'jk/credential-plug-leak' into maint
[gitweb.git] / alias.c
diff --git a/alias.c b/alias.c
index 372b7d809301f9e3e936459e405cd6f2627bd4a9..9938f03c255029ee8f5b10623e5e7bb65f2d7921 100644 (file)
--- a/alias.c
+++ b/alias.c
@@ -5,7 +5,7 @@ static char *alias_val;
 
 static int alias_lookup_cb(const char *k, const char *v, void *cb)
 {
-       if (!prefixcmp(k, "alias.") && !strcmp(k+6, alias_key)) {
+       if (!prefixcmp(k, "alias.") && !strcmp(k + 6, alias_key)) {
                if (!v)
                        return config_error_nonbool(k);
                alias_val = xstrdup(v);
@@ -22,12 +22,19 @@ char *alias_lookup(const char *alias)
        return alias_val;
 }
 
+#define SPLIT_CMDLINE_BAD_ENDING 1
+#define SPLIT_CMDLINE_UNCLOSED_QUOTE 2
+static const char *split_cmdline_errors[] = {
+       "cmdline ends with \\",
+       "unclosed quote"
+};
+
 int split_cmdline(char *cmdline, const char ***argv)
 {
        int src, dst, count = 0, size = 16;
        char quoted = 0;
 
-       *argv = xmalloc(sizeof(char *) * size);
+       *argv = xmalloc(sizeof(**argv) * size);
 
        /* split alias_string */
        (*argv)[count++] = cmdline;
@@ -38,7 +45,7 @@ int split_cmdline(char *cmdline, const char ***argv)
                        while (cmdline[++src]
                                        && isspace(cmdline[src]))
                                ; /* skip */
-                       ALLOC_GROW(*argv, count+1, size);
+                       ALLOC_GROW(*argv, count + 1, size);
                        (*argv)[count++] = cmdline + dst;
                } else if (!quoted && (c == '\'' || c == '"')) {
                        quoted = c;
@@ -53,7 +60,7 @@ int split_cmdline(char *cmdline, const char ***argv)
                                if (!c) {
                                        free(*argv);
                                        *argv = NULL;
-                                       return error("cmdline ends with \\");
+                                       return -SPLIT_CMDLINE_BAD_ENDING;
                                }
                        }
                        cmdline[dst++] = c;
@@ -66,12 +73,16 @@ int split_cmdline(char *cmdline, const char ***argv)
        if (quoted) {
                free(*argv);
                *argv = NULL;
-               return error("unclosed quote");
+               return -SPLIT_CMDLINE_UNCLOSED_QUOTE;
        }
 
-       ALLOC_GROW(*argv, count+1, size);
+       ALLOC_GROW(*argv, count + 1, size);
        (*argv)[count] = NULL;
 
        return count;
 }
 
+const char *split_cmdline_strerror(int split_cmdline_errno)
+{
+       return split_cmdline_errors[-split_cmdline_errno - 1];
+}