[committed] Fix second instance of BZ #18043
diff mbox

Message ID CALoOobPHBaKhgOp8tmUe=m68uHNkSLjBOCrGwVaPp4co-4O3Hg@mail.gmail.com
State New
Headers show

Commit Message

Paul Pluzhnikov March 9, 2015, 6:58 p.m. UTC
On Mon, Mar 9, 2015 at 11:19 AM, Paul Eggert <eggert@cs.ucla.edu> wrote:
> On 03/09/2015 07:28 AM, Paul Pluzhnikov wrote:
>>
>> -         if (strchr ("-=?+", words[1 + *offset]) == NULL)
>> +         if (words[1 + *offset] == '\0'
>> +             || strchr ("-=?+", words[1 + *offset]) == NULL)
>
>
> For stuff like this, how about using memchr instead?  E.g.,:

Sounds good to me. Something like attached?


2015-03-09  Paul Pluzhnikov  <ppluzhnikov@google.com>

        [BZ #18043]
        * posix/wordexp.c (CHAR_IN_SET): New macro.
        (parse_param): Use it.

Comments

Paul Eggert March 9, 2015, 9:08 p.m. UTC | #1
On 03/09/2015 11:58 AM, Paul Pluzhnikov wrote:
> +#define CHAR_IN_SET(ch, char_set) \
> +  (memchr (char_set "", (ch), sizeof (char_set) - 1) != NULL)

Yes, thanks, that looks good, except the parentheses are redundant in 
"(ch)".
Paul Pluzhnikov March 9, 2015, 9:43 p.m. UTC | #2
On Mon, Mar 9, 2015 at 2:08 PM, Paul Eggert <eggert@cs.ucla.edu> wrote:

> Yes, thanks, that looks good, except the parentheses are redundant in
> "(ch)".

Right. Committed as 01d032e0bb911f855963f75449e4fbe48e657292

Thanks,

Patch
diff mbox

diff --git a/posix/wordexp.c b/posix/wordexp.c
index 36b6fff..661dfd4 100644
--- a/posix/wordexp.c
+++ b/posix/wordexp.c
@@ -1218,6 +1218,9 @@  parse_comm (char **word, size_t *word_length, size_t *max_length,
   return WRDE_SYNTAX;
 }
 
+#define CHAR_IN_SET(ch, char_set) \
+  (memchr (char_set "", (ch), sizeof (char_set) - 1) != NULL)
+
 static int
 internal_function
 parse_param (char **word, size_t *word_length, size_t *max_length,
@@ -1299,7 +1302,7 @@  parse_param (char **word, size_t *word_length, size_t *max_length,
 	}
       while (isdigit(words[++*offset]));
     }
-  else if (words[*offset] != '\0' && strchr ("*@$", words[*offset]) != NULL)
+  else if (CHAR_IN_SET (words[*offset], "*@$"))
     {
       /* Special parameter. */
       special = 1;
@@ -1343,8 +1346,7 @@  parse_param (char **word, size_t *word_length, size_t *max_length,
 	  break;
 
 	case ':':
-	  if (words[1 + *offset] == '\0'
-	      || strchr ("-=?+", words[1 + *offset]) == NULL)
+	  if (!CHAR_IN_SET (words[1 + *offset], "-=?+"))
 	    goto syntax;
 
 	  colon_seen = 1;
@@ -2046,6 +2048,8 @@  do_error:
   return error;
 }
 
+#undef CHAR_IN_SET
+
 static int
 internal_function
 parse_dollars (char **word, size_t *word_length, size_t *max_length,