]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
fourth set of ANSI C changes: size_t; rest globskipdots to enabled default in subshells
authorChet Ramey <chet.ramey@case.edu>
Wed, 4 Jan 2023 14:18:59 +0000 (09:18 -0500)
committerChet Ramey <chet.ramey@case.edu>
Wed, 4 Jan 2023 14:18:59 +0000 (09:18 -0500)
16 files changed:
CWRU/CWRU.chlog
alias.c
bashline.c
braces.c
builtins/bind.def
builtins/shopt.def
builtins/type.def
execute_cmd.c
externs.h
input.h
lib/sh/stringlist.c
lib/sh/stringvec.c
parse.y
tests/shopt.right
variables.c
variables.h

index 92084e094ef1d79c973d953977f36aeaed8569f1..bad18c8c3d2d8d4e257e0ef0bf8301fe53d4b74d 100644 (file)
@@ -4902,3 +4902,32 @@ subst.c,findcmd.c
 arrayfunc.h,variables.h,findcmd.h,bashline.h,trap.h,pathexp.h,externs.h,
 pcomplete.h,bashhist.h,assoc.h,general.h,subst.h
        - more `const' changes, remove `register'
+
+                                   1/3
+                                   ---
+parse.y
+       - more `const' changes, remove `register'
+
+variables.h
+       - VARLIST: list_len and list_size now size_t
+
+variables.c
+       - vlist_alloc: take size_t parameter, changed callers
+       - vlist_realloc: take size_t parameter, changed callers
+
+lib/sh/stringvec.c,externs.h
+       - functions that take int size params now take size_t
+       - strvec_len: returns size_t
+
+lib/sh/stringlist.c,externs.h
+       - STRINGLIST: list_size and list_len now size_t
+       - functions that take int size params now take size_t
+
+variables.c,bashline.c,builtins/bind.def
+       - change strvec_ int parameters to size_t where it makes sense
+       - change strlist_ int parameters to size_t where it makes sense
+
+builtins/shopt.def
+       - reset_shopt_options: set glob_always_skip_dot_and_dotdot to 1,
+         since that's the current default in lib/glob/glob.c
+
diff --git a/alias.c b/alias.c
index a01496a1fea565753296fbaf9e2b51f61decac17..1c2a1303dee8f7550a802c83e7371fc0407ececa 100644 (file)
--- a/alias.c
+++ b/alias.c
@@ -464,7 +464,6 @@ char *
 
 alias_expand (char *string)
 {
-
   register int i, j, start;
   char *line, *token;
   int line_len, tl, real_start, expand_next, expand_this_token;
index cdff17c186864f5c61417bec2f28cb38463421ac..45046aee8b708509def69f9d438a59dee8f0ad2d 100644 (file)
@@ -753,10 +753,10 @@ display_shell_version (int count, int c)
 static char **hostname_list = (char **)NULL;
 
 /* The physical size of the above list. */
-static int hostname_list_size;
+static size_t hostname_list_size;
 
 /* The number of hostnames in the above list. */
-static int hostname_list_length;
+static size_t hostname_list_length;
 
 /* Whether or not HOSTNAME_LIST has been initialized. */
 int hostname_list_initialized = 0;
index 761406d9170126084ebd4865183cd7fdda5527bf..e21160c1c5d51dd00bd329458541ce359b424dd5 100644 (file)
--- a/braces.c
+++ b/braces.c
@@ -1,6 +1,6 @@
 /* braces.c -- code for doing word expansion in curly braces. */
 
-/* Copyright (C) 1987-2020,2022 Free Software Foundation, Inc.
+/* Copyright (C) 1987-2020,2022-2023 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
@@ -304,7 +304,8 @@ expand_amble (char *text, size_t tlen, int flags)
        result = partial;
       else
        {
-         register int lr, lp, j;
+         size_t lr, lp;
+         int j;
 
          lr = strvec_len (result);
          lp = strvec_len (partial);
@@ -711,8 +712,9 @@ comsub:
 static char **
 array_concat (char **arr1, char **arr2)
 {
-  register int i, j, len, len1, len2;
-  register char **result;
+  int i, j, len;
+  size_t len1, len2;
+  char **result;
 
   if (arr1 == 0)
     return (arr2);             /* XXX - see if we can get away without copying? */
index 367ef86a7f6070448b23c62989495a32bf44148d..99dd1fa97e78f50246bb95b39829741b8a9eca0d 100644 (file)
@@ -1,7 +1,7 @@
 This file is bind.def, from which is created bind.c.
 It implements the builtin "bind" in Bash.
 
-Copyright (C) 1987-2022 Free Software Foundation, Inc.
+Copyright (C) 1987-2023 Free Software Foundation, Inc.
 
 This file is part of GNU Bash, the Bourne Again SHell.
 
@@ -276,7 +276,8 @@ bind_builtin (WORD_LIST *list)
   /* Process the rest of the arguments as binding specifications. */
   while (list)
     {
-      int olen, nlen, d, i;
+      size_t olen, nlen;
+      int d, i;
       char **obindings, **nbindings;
 
       obindings = rl_invoking_keyseqs (bash_execute_unix_command);
index cf1187f376420f7e85bc54551eb0fcb533acdac8..8ecc56157c49cb6e9da149341d80feaa22567dac 100644 (file)
@@ -383,6 +383,7 @@ reset_shopt_options (void)
 #if defined (EXTENDED_GLOB)
   extended_glob = extglob_flag = EXTGLOB_DEFAULT;
 #endif
+  glob_always_skip_dot_and_dotdot = 1;         /* new default as of bash-5.2 */
 
 #if defined (ARRAY_VARS)
   expand_once_flag = assoc_expand_once = 0;
index 1e0fb4579bf939a7f1a4e6b8f41529c0dbe4f3d3..ad67a938d338a17bc0ef308b7fe8674cf79528c8 100644 (file)
@@ -76,8 +76,6 @@ $END
 #include "common.h"
 #include "bashgetopt.h"
 
-extern int find_reserved_word (char *);
-
 /* For each word in LIST, find out what the shell is going to do with
    it as a simple command. i.e., which file would this shell use to
    execve, or if it is a builtin command, or an alias.  Possible flag
index 7592d900334f42ee7f182dd28ce43ddd0b5e2f97..61ceb61b77941540aee0b881aa7ba7a5ce2cf519 100644 (file)
@@ -5836,9 +5836,9 @@ initialize_subshell (void)
 int
 shell_execve (char *command, char **args, char **env)
 {
-  int larray, i, fd;
+  int i, fd, sample_len;
   char sample[HASH_BANG_BUFSIZ];
-  int sample_len;
+  size_t larray;
 
   SETOSTYPE (0);               /* Some systems use for USG/POSIX semantics */
   execve (command, args, env);
index eded48bbc3b6e62316944d07fddcb2adce446688..db287a419d14149e2e40783a6ce60e520dd1d6c8 100644 (file)
--- a/externs.h
+++ b/externs.h
@@ -387,14 +387,14 @@ extern size_t strftime (char *, size_t, const char *, const struct tm *);
 /* This is a general-purpose argv-style array struct. */
 typedef struct _list_of_strings {
   char **list;
-  int list_size;
-  int list_len;
+  size_t list_size;
+  size_t list_len;
 } STRINGLIST;
 
 typedef int sh_strlist_map_func_t (char *);
 
-extern STRINGLIST *strlist_create (int);
-extern STRINGLIST *strlist_resize (STRINGLIST *, int);
+extern STRINGLIST *strlist_create (size_t);
+extern STRINGLIST *strlist_resize (STRINGLIST *, size_t);
 extern void strlist_flush (STRINGLIST *);
 extern void strlist_dispose (STRINGLIST *);
 extern int strlist_remove (STRINGLIST *, const char *);
@@ -408,14 +408,14 @@ extern void strlist_sort (STRINGLIST *);
 
 /* declarations for functions defined in lib/sh/stringvec.c */
 
-extern char **strvec_create (int);
-extern char **strvec_resize (char **, int);
-extern char **strvec_mcreate (int);
-extern char **strvec_mresize (char **, int);
+extern char **strvec_create (size_t);
+extern char **strvec_resize (char **, size_t);
+extern char **strvec_mcreate (size_t);
+extern char **strvec_mresize (char **, size_t);
 extern void strvec_flush (char **);
 extern void strvec_dispose (char **);
 extern int strvec_remove (char **, const char *);
-extern int strvec_len (char * const *);
+extern size_t strvec_len (char * const *);
 extern int strvec_search (char **, const char *);
 extern char **strvec_copy (char * const *);
 extern int strvec_posixcmp (char **, char **);
diff --git a/input.h b/input.h
index 5e9d92754442ce254fa9cb002a7d8e20c5f1f0cf..5fcfa7432c046a2fef7518885aea17667ec14832 100644 (file)
--- a/input.h
+++ b/input.h
@@ -102,9 +102,9 @@ extern void push_stream (int);
 extern void pop_stream (void);
 extern int stream_on_stack (enum stream_type);
 extern char *read_secondary_line (int);
-extern int find_reserved_word (char *);
+extern int find_reserved_word (const char *);
 extern void gather_here_documents (void);
-extern void execute_variable_command (char *, char *);
+extern void execute_variable_command (const char *, const char *);
 
 extern int *save_token_state (void);
 extern void restore_token_state (int *);
index da31ab896eeff2706dcb28ba3f77a5b653ef26e8..6cc2fac700a86112be6140593681b843fee6c734 100644 (file)
@@ -1,6 +1,6 @@
 /* stringlist.c - functions to handle a generic `list of strings' structure */
 
-/* Copyright (C) 2000-2019, 2022 Free Software Foundation, Inc.
+/* Copyright (C) 2000-2019, 2022-2023 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
@@ -37,7 +37,7 @@
 /* Allocate a new STRINGLIST, with room for N strings. */
 
 STRINGLIST *
-strlist_create (int n)
+strlist_create (size_t n)
 {
   STRINGLIST *ret;
   register int i;
@@ -60,7 +60,7 @@ strlist_create (int n)
 }
 
 STRINGLIST *
-strlist_resize (STRINGLIST *sl, int n)
+strlist_resize (STRINGLIST *sl, size_t n)
 {
   register int i;
 
index c06690ca8b1dc5e1990b146e8a82a1e8d5270191..9738ef464e7643506a65d3efab40325a6a52be1c 100644 (file)
@@ -1,6 +1,6 @@
 /* stringvec.c - functions for managing arrays of strings. */
 
-/* Copyright (C) 2000-2002,2022 Free Software Foundation, Inc.
+/* Copyright (C) 2000-2002,2022-2023 Free Software Foundation, Inc.
 
    This file is part of GNU Bash, the Bourne Again SHell.
 
 
 /* Allocate an array of strings with room for N members. */
 char **
-strvec_create (int n)
+strvec_create (size_t n)
 {
   return ((char **)xmalloc ((n) * sizeof (char *)));
 }
 
 /* Allocate an array of strings with room for N members. */
 char **
-strvec_mcreate (int n)
+strvec_mcreate (size_t n)
 {
   return ((char **)malloc ((n) * sizeof (char *)));
 }
 
 char **
-strvec_resize (char **array, int nsize)
+strvec_resize (char **array, size_t nsize)
 {
   return ((char **)xrealloc (array, nsize * sizeof (char *)));
 }
 
 char **
-strvec_mresize (char **array, int nsize)
+strvec_mresize (char **array, size_t nsize)
 {
   return ((char **)realloc (array, nsize * sizeof (char *)));
 }
 
 /* Return the length of ARRAY, a NULL terminated array of char *. */
-int
+size_t
 strvec_len (char * const *array)
 {
   register int i;
diff --git a/parse.y b/parse.y
index 8f330897c1fe8303985b62052418180a0861e2fd..2fffd2b47e2561a97e511ac8ef37c575b62c125d 100644 (file)
--- a/parse.y
+++ b/parse.y
@@ -174,10 +174,10 @@ static int reserved_word_acceptable (int);
 static int yylex (void);
 
 static void push_heredoc (REDIRECT *);
-static char *mk_alexpansion (char *);
-static int alias_expand_token (char *);
+static char *mk_alexpansion (const char *);
+static int alias_expand_token (const char *);
 static int time_command_acceptable (void);
-static int special_case_tokens (char *);
+static int special_case_tokens (const char *);
 static int read_token (int);
 static char *parse_matched_pair (int, int, int, int *, int);
 static char *parse_comsub (int, int, int, int *, int);
@@ -198,7 +198,7 @@ static int cond_skip_newlines (void);
 static COMMAND *parse_cond_command (void);
 #endif
 #if defined (ARRAY_VARS)
-static int token_is_assignment (char *, int);
+static int token_is_assignment (const char *, int);
 static int token_is_ident (char *, int);
 #endif
 static int read_token_word (int);
@@ -207,7 +207,7 @@ static void discard_parser_constructs (int);
 static char *error_token_from_token (int);
 static char *error_token_from_text (void);
 static void print_offending_line (void);
-static void report_syntax_error (char *);
+static void report_syntax_error (const char *);
 
 static void handle_eof_input_unit (void);
 static void prompt_again (int);
@@ -1622,8 +1622,8 @@ with_input_from_stdin (void)
 static int
 yy_string_get (void)
 {
-  register char *string;
-  register unsigned char c;
+  char *string;
+  unsigned char c;
 
   string = bash_input.location.string;
 
@@ -2805,7 +2805,7 @@ discard_until (int character)
 }
 
 void
-execute_variable_command (char *command, char *vname)
+execute_variable_command (const char *command, const char *vname)
 {
   char *last_lastarg;
   sh_parser_state_t ps;
@@ -3013,7 +3013,7 @@ static int open_brace_count;
         In a pattern list in a case statement (parser_state & PST_CASEPAT). */
 
 static char *
-mk_alexpansion (char *s)
+mk_alexpansion (const char *s)
 {
   int l;
   char *r;
@@ -3035,7 +3035,7 @@ mk_alexpansion (char *s)
 }
 
 static int
-alias_expand_token (char *tokstr)
+alias_expand_token (const char *tokstr)
 {
   char *expanded;
   alias_t *ap;
@@ -3150,7 +3150,7 @@ time_command_acceptable (void)
 */
 
 static int
-special_case_tokens (char *tokstr)
+special_case_tokens (const char *tokstr)
 {
   /* Posix grammar rule 6 */
   if ((last_read_token == WORD) &&
@@ -4768,7 +4768,7 @@ parse_cond_command (void)
    substitution that will reallocate atoken.  We don't want to write beyond
    the end of an allocated buffer. */
 static int
-token_is_assignment (char *t, int i)
+token_is_assignment (const char *t, int i)
 {
   int r;
   char *atoken;
@@ -5367,7 +5367,7 @@ reserved_word_acceptable (int toksym)
 /* Return the index of TOKEN in the alist of reserved words, or -1 if
    TOKEN is not a shell reserved word. */
 int
-find_reserved_word (char *tokstr)
+find_reserved_word (const char *tokstr)
 {
   int i;
   for (i = 0; word_token_alist[i].word; i++)
@@ -6172,7 +6172,7 @@ print_offending_line (void)
    then place it in MESSAGE, otherwise pass NULL and this will figure
    out an appropriate message for you. */
 static void
-report_syntax_error (char *message)
+report_syntax_error (const char *message)
 {
   char *msg, *p;
 
index d617c1d720c83cc9697dd2d82848348af67681bc..640f75d2642a253e50ff1903222153eab996da69 100644 (file)
@@ -304,9 +304,5 @@ xtrace              off
 --
 ./shopt.tests: line 106: shopt: xyz1: invalid shell option name
 ./shopt.tests: line 107: shopt: xyz1: invalid option name
-28c28
-< globskipdots         off
----
-> globskipdots         on
 expand_aliases         on
 expand_aliases         on
index 24f3ef8c8d1fd4083d01310d2156f103366f47df..8f112807350336935cb706526005511605f74c13 100644 (file)
@@ -175,7 +175,7 @@ int shell_level = 0;
    shell variables that are marked for export. */
 char **export_env = (char **)NULL;
 static int export_env_index;
-static int export_env_size;
+static size_t export_env_size;
 
 #if defined (READLINE)
 static int winsize_assignment;         /* currently assigning to LINES or COLUMNS */
@@ -284,8 +284,8 @@ static SHELL_VAR *bind_variable_internal (const char *, const char *, HASH_TABLE
 static void dispose_variable_value (SHELL_VAR *);
 static void free_variable_hash_data (PTR_T);
 
-static VARLIST *vlist_alloc (int);
-static VARLIST *vlist_realloc (VARLIST *, int);
+static VARLIST *vlist_alloc (size_t);
+static VARLIST *vlist_realloc (VARLIST *, size_t);
 static void vlist_add (VARLIST *, SHELL_VAR *, int);
 
 static void flatten (HASH_TABLE *, sh_var_map_func_t *, VARLIST *, int);
@@ -4037,7 +4037,7 @@ set_func_auto_export (const char *name)
 /* **************************************************************** */
 
 static VARLIST *
-vlist_alloc (int nentries)
+vlist_alloc (size_t nentries)
 {
   VARLIST  *vlist;
 
@@ -4051,7 +4051,7 @@ vlist_alloc (int nentries)
 }
 
 static VARLIST *
-vlist_realloc (VARLIST *vlist, int n)
+vlist_realloc (VARLIST *vlist, size_t n)
 {
   if (vlist == 0)
     return (vlist = vlist_alloc (n));
@@ -4090,7 +4090,7 @@ map_over (sh_var_map_func_t *function, VAR_CONTEXT *vc)
   VAR_CONTEXT *v;
   VARLIST *vlist;
   SHELL_VAR **ret;
-  int nentries;
+  size_t nentries;
 
   for (nentries = 0, v = vc; v; v = v->down)
     nentries += HASH_ENTRIES (v->table);
@@ -4334,7 +4334,8 @@ all_variables_matching_prefix (const char *prefix)
 {
   SHELL_VAR **varlist;
   char **rlist;
-  int vind, rind, plen;
+  int rind, plen;
+  size_t vind;
 
   plen = STRLEN (prefix);
   varlist = all_visible_variables ();
index 63779fd756906d48960b58210b37d7126a2b5f6e..1616d45519dcd0f0d6a737e5f63188bf0d62cf20 100644 (file)
@@ -95,8 +95,8 @@ typedef struct variable {
 
 typedef struct _vlist {
   SHELL_VAR **list;
-  int list_size;       /* allocated size */
-  int list_len;                /* current number of entries */
+  size_t list_size;    /* allocated size */
+  size_t list_len;     /* current number of entries */
 } VARLIST;
 
 /* The various attributes that a given variable can have. */