]> git.ipfire.org Git - thirdparty/git.git/blobdiff - compat/mingw.c
mingw: fix quoting of arguments
[thirdparty/git.git] / compat / mingw.c
index 8b6fa0db446aee9888ff6484560131143c7e22e5..459ee20df66ea844c60ba68c9a3d0e3b439e1290 100644 (file)
@@ -872,7 +872,7 @@ static const char *quote_arg(const char *arg)
                                p++;
                                len++;
                        }
-                       if (*p == '"')
+                       if (*p == '"' || !*p)
                                n += count*2 + 1;
                        continue;
                }
@@ -894,16 +894,19 @@ static const char *quote_arg(const char *arg)
                                count++;
                                *d++ = *arg++;
                        }
-                       if (*arg == '"') {
+                       if (*arg == '"' || !*arg) {
                                while (count-- > 0)
                                        *d++ = '\\';
+                               /* don't escape the surrounding end quote */
+                               if (!*arg)
+                                       break;
                                *d++ = '\\';
                        }
                }
                *d++ = *arg++;
        }
        *d++ = '"';
-       *d++ = 0;
+       *d++ = '\0';
        return q;
 }