]> git.ipfire.org Git - thirdparty/bash.git/blobdiff - alias.c
Bash-5.1 patch 4: fix key-value pair associative array assignment word expansions
[thirdparty/bash.git] / alias.c
diff --git a/alias.c b/alias.c
index 7839229659e9c3159c2a5c2e3b823e7757d25ba1..cd5e99b7e04e54b9b303b10f4e59e780b1fd869a 100644 (file)
--- a/alias.c
+++ b/alias.c
@@ -1,7 +1,7 @@
 /* alias.c -- Not a full alias, but just the kind that we use in the
    shell.  Csh style alias is somewhere else (`over there, in a box'). */
 
-/* Copyright (C) 1987-2009 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2020 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
 #  include "pcomplete.h"
 #endif
 
-#define ALIAS_HASH_BUCKETS     16      /* must be power of two */
+#if defined (HAVE_MBSTR_H) && defined (HAVE_MBSCHR)
+#  include <mbstr.h>           /* mbschr */
+#endif
+
+#define ALIAS_HASH_BUCKETS     64      /* must be power of two */
 
-typedef int sh_alias_map_func_t __P((alias_t *));
+typedef int sh_alias_map_func_t PARAMS((alias_t *));
 
-static void free_alias_data __P((PTR_T));
-static alias_t **map_over_aliases __P((sh_alias_map_func_t *));
-static void sort_aliases __P((alias_t **));
-static int qsort_alias_compare __P((alias_t **, alias_t **));
+static void free_alias_data PARAMS((PTR_T));
+static alias_t **map_over_aliases PARAMS((sh_alias_map_func_t *));
+static void sort_aliases PARAMS((alias_t **));
+static int qsort_alias_compare PARAMS((alias_t **, alias_t **));
 
 #if defined (READLINE)
-static int skipquotes __P((char *, int));
-static int skipws __P((char *, int));
-static int rd_token __P((char *, int));
+static int skipquotes PARAMS((char *, int));
+static int skipws PARAMS((char *, int));
+static int rd_token PARAMS((char *, int));
 #endif
 
 /* Non-zero means expand all words on the line.  Otherwise, expand
@@ -123,9 +127,12 @@ add_alias (name, value)
       free (temp->value);
       temp->value = savestring (value);
       temp->flags &= ~AL_EXPANDNEXT;
-      n = value[strlen (value) - 1];
-      if (n == ' ' || n == '\t')
-       temp->flags |= AL_EXPANDNEXT;
+      if (value[0])
+       {
+         n = value[strlen (value) - 1];
+         if (n == ' ' || n == '\t')
+           temp->flags |= AL_EXPANDNEXT;
+       }
     }
   else
     {
@@ -134,9 +141,12 @@ add_alias (name, value)
       temp->value = savestring (value);
       temp->flags = 0;
 
-      n = value[strlen (value) - 1];
-      if (n == ' ' || n == '\t')
-       temp->flags |= AL_EXPANDNEXT;
+      if (value[0])
+       {
+         n = value[strlen (value) - 1];
+         if (n == ' ' || n == '\t')
+           temp->flags |= AL_EXPANDNEXT;
+       }
 
       elt = hash_insert (savestring (name), aliases, HASH_NOSRCH);
       elt->data = temp;
@@ -154,6 +164,10 @@ free_alias_data (data)
   register alias_t *a;
 
   a = (alias_t *)data;
+
+  if (a->flags & AL_BEINGEXPANDED)
+    clear_string_list_expander (a);    /* call back to the parser */
+
   free (a->value);
   free (a->name);
   free (data);