bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH] Use strdup in dd to avoid changing argv elements


From: Jim Meyering
Subject: Re: [PATCH] Use strdup in dd to avoid changing argv elements
Date: Thu, 31 Jan 2008 09:27:53 +0100

Paul Eggert <address@hidden> wrote:
...
> You're welcome, but it turns out that I missed a case: commas in
...
> 2008-01-30  Paul Eggert  <address@hidden>
>
>       Don't modify argv in dd due to ',' in arguments.
>       * src/dd.c: Include quotearg.h.
>       (operand_matches): New function.
>       (parse_symbols, operand_is): Use it.
>       (parse_symbols): 1st arg is now const pointer.  Don't modify it.
>       msgid arg is now just the message, not a format.
>       (scanargs): Add some 'const's to check for problems like the above.

Thanks for your vigilance.
I've applied that, with these cosmetic changes:

diff --git a/src/dd.c b/src/dd.c
index 4a8419d..c40d0ee 100644
--- a/src/dd.c
+++ b/src/dd.c
@@ -1,5 +1,5 @@
 /* dd -- convert a file while copying it.
-   Copyright (C) 85, 90, 91, 1995-2007 Free Software Foundation, Inc.
+   Copyright (C) 85, 90, 91, 1995-2008 Free Software Foundation, Inc.

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -810,8 +810,7 @@ operand_matches (char const *str, char const *pattern, char 
delim)

 /* Interpret one "conv=..." or similar operand STR according to the
    symbols in TABLE, returning the flags specified.  If the operand
-   cannot be parsed, use ERROR_MSGID to generate a diagnostic.
-   As a by product, this function replaces each `,' in STR with a NUL byte.  */
+   cannot be parsed, use ERROR_MSGID to generate a diagnostic.  */

 static int
 parse_symbols (char const *str, struct symbol_value const *table,
@@ -827,13 +826,15 @@ parse_symbols (char const *str, struct symbol_value const 
*table,
       for (entry = table;
           ! (operand_matches (str, entry->symbol, ',') && entry->value);
           entry++)
-       if (! entry->symbol[0])
-         {
-           size_t slen = strcomma ? strcomma - str : strlen (str);
-           error (0, 0, "%s: %s", _(error_msgid),
-                  quotearg_n_style_mem (0, locale_quoting_style, str, slen));
-           usage (EXIT_FAILURE);
-         }
+       {
+         if (! entry->symbol[0])
+           {
+             size_t slen = strcomma ? strcomma - str : strlen (str);
+             error (0, 0, "%s: %s", _(error_msgid),
+                    quotearg_n_style_mem (0, locale_quoting_style, str, slen));
+             usage (EXIT_FAILURE);
+           }
+       }

       value |= entry->value;
       if (!strcomma)




reply via email to

[Prev in Thread] Current Thread [Next in Thread]