]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
(quote_filename): Allocate two more bytes (for quotes)
authorJim Meyering <jim@meyering.net>
Thu, 6 Feb 1997 03:58:09 +0000 (03:58 +0000)
committerJim Meyering <jim@meyering.net>
Thu, 6 Feb 1997 03:58:09 +0000 (03:58 +0000)
when using --quote-name (-Q).
Feb 2 change wasn't complete.  Patch from Mark Harris.

src/ls.c

index 9a16e30bec873f2d58bac54a86eec0a295124de6..fc0b7b544850ee2ff7c47aee2f4c306d7f408b04 100644 (file)
--- a/src/ls.c
+++ b/src/ls.c
@@ -2230,7 +2230,12 @@ quote_filename (register const char *p, size_t *quoted_length)
     }
 
   p = p0;
-  quoted = xmalloc (4 * strlen (p) + 1);
+
+  quoted = xmalloc (4 * strlen (p)
+                   /* Add two (one for beginning and one for ending quote)
+                      if --quote-name (-Q) was specified.  */
+                   + (quote_as_string ? 2 : 0)
+                   + 1);
   q = quoted;
 
 #define SAVECHAR(c) *q++ = (c)
@@ -2276,7 +2281,9 @@ quote_filename (register const char *p, size_t *quoted_length)
              break;
 
            case '"':
-             SAVE_2_CHARS ("\\\"");
+             if (quote_as_string)
+               SAVECHAR ('\\');
+             SAVECHAR ('"');
              break;
 
            default: