]> git.ipfire.org Git - thirdparty/bash.git/commitdiff
set of portability changes from lint/asan/ubsan
authorChet Ramey <chet.ramey@case.edu>
Sat, 7 Jan 2023 18:18:20 +0000 (13:18 -0500)
committerChet Ramey <chet.ramey@case.edu>
Sat, 7 Jan 2023 18:18:20 +0000 (13:18 -0500)
35 files changed:
CWRU/CWRU.chlog
Makefile.in
array.c
bashline.c
bracecomp.c
builtins/echo.def
builtins/enable.def
builtins/getopt.c
builtins/help.def
builtins/printf.def
builtins/set.def
examples/loadables/print.c
execute_cmd.c
execute_cmd.h
expr.c
externs.h
general.c
general.h
lib/glob/sm_loop.c
lib/readline/bind.c
lib/readline/complete.c
lib/readline/display.c
lib/readline/funmap.c
lib/readline/histfile.c
lib/readline/isearch.c
lib/readline/vi_mode.c
lib/sh/pathphys.c
lib/sh/shquote.c
lib/sh/stringvec.c
lib/sh/strtrans.c
lib/tilde/tilde.c
locale.c
parse.y
stringlib.c
subst.c

index 222fc2c1a9d8f057ea27f643c68ea4d261726647..6a0741943bc55137353fd44cb33e4d2ed140901b 100644 (file)
@@ -4951,3 +4951,30 @@ lib/readline/mbutil.c,lib/tilde/tilde.c
        - size_t changes
        - remove some unused variables
        - remove `register'
+
+                                   1/5
+                                   ---
+builtins/getopt.c
+       - sh_getopt_restore_state: make sure argv[sh_curopt] is non-null before
+         using it
+
+parse.y
+       - CHECK_FOR_RESERVED_WORD: make sure to set word_top appropriately if
+         the last token was IF, WHILE, or UNTIL, since these tokens can follow
+         those reserved words
+
+Makefile.in
+       - ubsan: new target, to build with gcc/clang UBSan undefined behavior
+         sanitizer
+
+                                   1/6
+                                   ---
+execute_cmd.[ch],locale.c,parse.y,expr.c,bracecomp.c,bashline.c,externs.h
+stringlib.c,general.[ch]
+builtins/{subst.c,array.c,echo.def,printf.def,enable.def,help.def,set.def}
+lib/sh/{strtrans.c,stringvec.c,shquote.c}
+lib/glob/sm_loop.c
+lib/readline/{vi_mode.c,histfile.c,funmap.c,complete.c,display.c,bind.c,isearch.c}
+lib/tilde/tilde.c
+       - final code cleanups for ANSI C and lint/ubsan/asan runs
+
index b7d92fd455583978e172f143471511c5fd088e0c..a51f3359f81409f5698a668c8eeda2226cec961a 100644 (file)
@@ -166,6 +166,9 @@ LDFLAGS_FOR_BUILD = @LDFLAGS_FOR_BUILD@ $(LOCAL_LDFLAGS) $(CFLAGS_FOR_BUILD)
 ASAN_XCFLAGS = -fsanitize=address -fno-omit-frame-pointer
 ASAN_XLDFLAGS = -fsanitize=address
 
+UBSAN_XCFLAGS = -fsanitize=undefined -fsanitize-recover -fstack-protector
+UBSAN_XLDFLAGS = -fsanitize=undefined
+
 GCOV_XCFLAGS = -fprofile-arcs -ftest-coverage
 GCOV_XLDFLAGS = -fprofile-arcs -ftest-coverage
 
@@ -174,7 +177,7 @@ INCLUDES = -I. @RL_INCLUDE@ -I$(srcdir) -I$(BASHINCDIR) -I$(LIBSRC) $(INTL_INC)
 # Maybe add: -Wextra
 GCC_LINT_FLAGS = -O -Wall -Wshadow -Wpointer-arith -Wcast-qual -Wno-parentheses \
                 -Wcast-align -Wstrict-prototypes -Wconversion -Wformat \
-                -Wformat-nonliteral -Wmissing-braces -Wuninitialized \
+                -Wmissing-braces -Wuninitialized \
                 -Wmissing-declarations  -Winline \
                 -Wmissing-prototypes -Wredundant-decls \
                 -Wformat-security -pedantic
@@ -621,6 +624,9 @@ lint:
 asan:
        ${MAKE} ${MFLAGS} ADDON_CFLAGS='${ASAN_XCFLAGS}' ADDON_LDFLAGS='${ASAN_XLDFLAGS}' .made
 
+ubsan:
+       ${MAKE} ${MFLAGS} ADDON_CFLAGS='${UBSAN_XCFLAGS}' ADDON_LDFLAGS='${UBSAN_XLDFLAGS}' .made
+
 valgrind:
        ${MAKE} ${MFLAGS} ADDON_CFLAGS='-DDISABLE_MALLOC_WRAPPERS' ADDON_LDFLAGS= .made
 
diff --git a/array.c b/array.c
index 85e2965542b25c89f28cbd4049dae3911fbc084a..61894e0b89cc8e7a941d8c569da1880b783b921f 100644 (file)
--- a/array.c
+++ b/array.c
@@ -814,7 +814,7 @@ array_from_argv(ARRAY *a, char **vec, int count)
   if (a == 0 || array_num_elements (a) == 0)
     {
       for (i = 0; i < count; i++)
-       array_insert (a, i, t);
+       array_insert (a, i, vec[i]);
       return a;
     }
 
index 611829528d5390665950aa411071afc8192408cc..75a5ec69140e919b1f70a97151ff3c1fa172b08b 100644 (file)
@@ -887,8 +887,9 @@ clear_hostname_list (void)
 static char **
 hostnames_matching (const char *text)
 {
-  register int i, len, nmatch, rsize;
+  int i, nmatch;
   char **result;
+  size_t rsize, len;
 
   if (hostname_list_initialized == 0)
     initialize_hostname_list ();
index 110bb078356e146543db31193ec2845ce087922c..1effa9aa70a4c83fbe9c4a3f8afbb6606108545b 100644 (file)
@@ -66,7 +66,8 @@ really_munge_braces (char **array, int real_start, int real_end, int gcd_zero)
 {
   int start, end, gcd;
   char *result, *subterm, *x;
-  int result_size, flag, tlen;
+  size_t result_size;
+  int flag, tlen;
 
   flag = 0;
 
index ae69b76a8045289fed92a07a35ba52f64c6824e4..37b0bbac18c4230ee9f8e68fe00dc7f90c2229f4 100644 (file)
@@ -109,7 +109,8 @@ int xpg_echo = 0;
 int
 echo_builtin (WORD_LIST *list)
 {
-  int display_return, do_v9, i, len;
+  int display_return, do_v9, i;
+  size_t len;
   char *temp, *s;
 
   do_v9 = xpg_echo;
index 6b5b5d9f80502bb00d6843175199d5539d4413b0..c1c5e673b91289445b74048d1bcdedc8404748fd 100644 (file)
@@ -319,8 +319,8 @@ dyn_load_builtin (WORD_LIST *list, int flags, char *filename)
   WORD_LIST *l;
   void *handle;
   
-  int total, new, replaced, r;
-  size_t size;
+  int total, replaced, r;
+  size_t size, new;
   char *struct_name, *name, *funcname;
   sh_load_func_t *loadfunc;
   struct builtin **new_builtins, *b, *new_shell_builtins, *old_builtin;
@@ -381,7 +381,7 @@ dyn_load_builtin (WORD_LIST *list, int flags, char *filename)
   /* For each new builtin in the shared object, find it and its describing
      structure.  If this is overwriting an existing builtin, do so, otherwise
      save the loaded struct for creating the new list of builtins. */
-  for (replaced = new = 0; list; list = list->next)
+  for (replaced = 0, new = 0; list; list = list->next)
     {
       name = list->word->word;
 
index d911877ec2d2f1d1a6ee651f29694a021a9bbd81..6fbb6edb15be6189ebaf34eeda7747e04edf81e6 100644 (file)
@@ -215,7 +215,7 @@ sh_getopt (int argc, char *const *argv, const char *optstring)
 void
 sh_getopt_restore_state (char **argv)
 {
-  if (nextchar)
+  if (nextchar && argv && argv[sh_curopt])
     nextchar = argv[sh_curopt] + sh_charindex;
 }
 
index 40eb5fb39f40c0caa5532c05187e4bfea9f1e833..293f23de8bc946194a2e041d9903852cf5bd1573 100644 (file)
@@ -254,10 +254,10 @@ static void
 show_desc (char *name, int i)
 {
   register int j, r;
-  char **doc, *line;
+  char * const *doc, *line;
   int fd, usefile;
 
-  doc = (char **)shell_builtins[i].long_doc;
+  doc = shell_builtins[i].long_doc;
 
   usefile = (doc && doc[0] && *doc[0] == '/' && doc[1] == (char *)NULL);
   if (usefile)
index 090e8179ef6cbc665792cf0f3a47ad1d898fc148..caa30ba1758895c9b6696a03f1b9b3858c469830 100644 (file)
@@ -469,7 +469,8 @@ printf_builtin (WORD_LIST *list)
            case '(':
              {
                char *timefmt, timebuf[TIMELEN_MAX], *t;
-               int n;
+               size_t n;
+               int r;
                intmax_t arg;
                time_t secs;
                struct tm *tm;
@@ -529,8 +530,8 @@ printf_builtin (WORD_LIST *list)
                /* convert to %s format that preserves fieldwidth and precision */
                modstart[0] = 's';
                modstart[1] = '\0';
-               n = printstr (start, timebuf, strlen (timebuf), fieldwidth, precision); /* XXX - %s for now */
-               if (n < 0)
+               r = printstr (start, timebuf, strlen (timebuf), fieldwidth, precision); /* XXX - %s for now */
+               if (r < 0)
                  {
                    if (ferror (stdout) == 0)
                      {
index 5852a8e68e8f24a52e54d9f8f6d870f251888443..b3e898c96387c2f82f543ee27407fa2f8cc9cf6a 100644 (file)
@@ -328,7 +328,8 @@ char *
 get_current_options (void)
 {
   char *temp;
-  int i, posixopts;
+  int i;
+  size_t posixopts;
 
   posixopts = num_posix_options ();    /* shopts modified by posix mode */
   /* Make the buffer big enough to hold the set -o options and the shopt
@@ -972,6 +973,7 @@ unset_builtin (WORD_LIST *list)
                  int len;
 
                  tname = savestring (nameref_cell (var));
+                 tem = 0;
                  if (var = array_variable_part (tname, 0, &t, &len))
                    {
                      /* change to what unbind_array_element now expects */
index 9b2f622858717681dc7f80f6c9134dc788366f39..d5901c50ace841ddafa0be83912d196b8333f4d9 100644 (file)
@@ -3,7 +3,7 @@
  */
 
 /*
-   Copyright (C) 1999-2009,2022 Free Software Foundation, Inc.
+   Copyright (C) 1999-2009,2022,2023 Free Software Foundation, Inc.
 
    This file is part of GNU Bash.
    Bash is free software: you can redistribute it and/or modify
@@ -177,7 +177,7 @@ printargs (WORD_LIST *list, FILE *ofp)
 
   for (sawc = 0, l = list; l; l = l->next)
     {
-      ostr = ansicstr (l->word->word, strlen (l->word->word), 0, &sawc, (int *)0);
+      ostr = ansicstr (l->word->word, strlen (l->word->word), 0, &sawc, 0);
       if (ostr)
        fprintf (ofp, "%s", ostr);
       free (ostr);
index a30ec61d0b4acbeae5603c262beffb5896f8938d..4b9208f47a25168c1cac144764a247ec9f47ac43 100644 (file)
@@ -350,7 +350,7 @@ dispose_fd_bitmap (struct fd_bitmap *fdbp)
 void
 close_fd_bitmap (struct fd_bitmap *fdbp)
 {
-  register int i;
+  int i;
 
   if (fdbp)
     {
@@ -520,7 +520,7 @@ restore_signal_mask (sigset_t *set)
 void
 open_files (void)
 {
-  register int i;
+  int i;
   int f, fd_table_size;
 
   fd_table_size = getdtablesize ();
@@ -2312,7 +2312,7 @@ coproc_setvars (struct coproc *cp)
 void
 coproc_unsetvars (struct coproc *cp)
 {
-  int l;
+  size_t l;
   char *namevar;
 
   if (cp->c_name == 0)
@@ -2819,7 +2819,7 @@ execute_connection (COMMAND *command, int asynchronous, int pipe_in, int pipe_ou
 static int
 execute_for_command (FOR_COM *for_command)
 {
-  register WORD_LIST *releaser, *list;
+  WORD_LIST *releaser, *list;
   SHELL_VAR *v;
   char *identifier;
   int retval, save_line_number;
@@ -3172,8 +3172,8 @@ displen (const char *s)
 static int
 print_index_and_element (int len, int ind, WORD_LIST *list)
 {
-  register WORD_LIST *l;
-  register int i;
+  WORD_LIST *l;
+  int i;
 
   if (list == 0)
     return (0);
@@ -3467,7 +3467,7 @@ execute_select_command (SELECT_COM *select_command)
 static int
 execute_case_command (CASE_COM *case_command)
 {
-  register WORD_LIST *list;
+  WORD_LIST *list;
   WORD_LIST *wlist, *es;
   PATTERN_LIST *clauses;
   char *word, *pattern;
@@ -5681,7 +5681,7 @@ parent_return:
 static char *
 getinterp (char *sample, int sample_len, int *endp)
 {
-  register int i;
+  int i;
   char *execname;
   int start;
 
@@ -6049,7 +6049,7 @@ execute_intern_function (WORD_DESC *name, FUNCTION_DEF *funcdef)
 void
 close_all_files (void)
 {
-  register int i, fd_table_size;
+  int i, fd_table_size;
 
   fd_table_size = getdtablesize ();
   if (fd_table_size > 256)     /* clamp to a reasonable value */
index 8152a4a8fd4523fdca6516d446820b48c6b6719b..37e386ab1e8cf116f31ae8a52ebb128f6ef0c192 100644 (file)
@@ -42,7 +42,6 @@ struct execstate
     pid_t pid;
     int subshell_env;
   };
-       
 
 /* Variables declared in execute_cmd.c, used by many other files */
 extern int return_catch_flag;
diff --git a/expr.c b/expr.c
index a8c2aa91cfe321c20d0aae58f3fd4524aa759a4d..1b4e465872ac2b5dd0f32b94e4f0e97580127955 100644 (file)
--- a/expr.c
+++ b/expr.c
@@ -445,9 +445,9 @@ static intmax_t
 subexpr (const char *expr)
 {
   intmax_t val;
-  char *p;
+  const char *p;
 
-  for (p = (char *)expr; p && *p && cr_whitespace (*p); p++)
+  for (p = expr; p && *p && cr_whitespace (*p); p++)
     ;
 
   if (p == NULL || *p == '\0')
index d38bcb7f29247f5971834f0be8dc06821ee32d79..535feb3c0d5a72206f5c1d1009cbf618fce25fff 100644 (file)
--- a/externs.h
+++ b/externs.h
@@ -142,9 +142,9 @@ extern int set_locale_var (const char *, const char *);
 extern int set_lang (const char *, const char *);
 extern void set_default_lang (void);
 extern char *get_locale_var (const char *);
-extern char *localetrans (const char *, int, int *);
+extern char *localetrans (const char *, int, size_t *);
 extern char *mk_msgstr (char *, int *);
-extern char *locale_expand (const char *, int, int, int, int *);
+extern char *locale_expand (const char *, int, int, int, size_t *);
 #ifndef locale_decpoint
 extern int locale_decpoint (void);
 #endif
@@ -169,7 +169,7 @@ extern char *strsub (const char *, const char *, const char *, int);
 extern char *strcreplace (const char *, int, const char *, int);
 extern void strip_leading (char *);
 extern void strip_trailing (char *, int, int);
-extern void xbcopy (char *, char *, size_t);
+extern void xbcopy (const void *, void *, size_t);
 
 /* Functions from version.c. */
 extern char *shell_version_string (void);
@@ -471,10 +471,10 @@ extern uintmax_t strtoumax (const char *, char **, int);
 #endif
 
 /* declarations for functions defined in lib/sh/strtrans.c */
-extern char *ansicstr (const char *, int, int, int *, int *);
+extern char *ansicstr (const char *, size_t, int, int *, size_t *);
 extern char *ansic_quote (const char *, int, int *);
 extern int ansic_shouldquote (const char *);
-extern char *ansiexpand (const char *, int, int, int *);
+extern char *ansiexpand (const char *, int, int, size_t *);
 
 /* declarations for functions defined in lib/sh/strvis.c */
 extern int sh_charvis (const char *, size_t *, size_t, char *, size_t *);
index be883cf81a1d2f058c1654f6b2a25b4ecd57e605..9c393dd94d149c66095dacb519ed9d144e848782 100644 (file)
--- a/general.c
+++ b/general.c
@@ -128,7 +128,7 @@ posix_initialize (int on)
     }
 }
 
-int
+size_t
 num_posix_options (void)
 {
   return ((sizeof (posix_vars) / sizeof (posix_vars[0])) - 1);
index 42563e567affecb18e39007a98fc981e280833fa..7f83d1f502e0f76312ff98e1ff82db7eb25dd720 100644 (file)
--- a/general.h
+++ b/general.h
@@ -301,7 +301,7 @@ extern void xfree (void *);
 /* Declarations for functions defined in general.c */
 extern void posix_initialize (int);
 
-extern int num_posix_options (void);
+extern size_t num_posix_options (void);
 extern char *get_posix_options (char *);
 extern void set_posix_options (const char *);
 
index c79097e1e862317afd69175e70d460e2ad89d113..01910805b71586eeff6842e934cac7f56e809075 100644 (file)
@@ -113,7 +113,7 @@ fprintf(stderr, "gmatch: pattern = %s; pe = %s\n", pattern, pe);
             we are matching a pathname. */
          if ((flags & FNM_DOTDOT) &&
              ((n == string && SDOT_OR_DOTDOT(n)) ||
-              ((flags & FNM_PATHNAME) && n[-1] == L('/') && PDOT_OR_DOTDOT(n))))
+              ((flags & FNM_PATHNAME) && n > string && n[-1] == L('/') && PDOT_OR_DOTDOT(n))))
            return FNM_NOMATCH;
 
          break;
@@ -159,7 +159,7 @@ fprintf(stderr, "gmatch: pattern = %s; pe = %s\n", pattern, pe);
             we are matching a pathname. */
          if ((flags & FNM_DOTDOT) &&
              ((n == string && SDOT_OR_DOTDOT(n)) ||
-              ((flags & FNM_PATHNAME) && n[-1] == L('/') && PDOT_OR_DOTDOT(n))))
+              ((flags & FNM_PATHNAME) && n > string && n[-1] == L('/') && PDOT_OR_DOTDOT(n))))
            return FNM_NOMATCH;
 
          if (p == pe)
@@ -346,7 +346,7 @@ fprintf(stderr, "gmatch: pattern = %s; pe = %s\n", pattern, pe);
               we are matching a pathname. */
            if ((flags & FNM_DOTDOT) &&
                ((n == string && SDOT_OR_DOTDOT(n)) ||
-               ((flags & FNM_PATHNAME) && n[-1] == L('/') && PDOT_OR_DOTDOT(n))))
+               ((flags & FNM_PATHNAME) && n > string && n[-1] == L('/') && PDOT_OR_DOTDOT(n))))
              return FNM_NOMATCH;
 
            p = BRACKMATCH (p, sc, flags);
index 157efb2a41f4b0ecaa36923af3dec478041f780d..967789381f27e6051fdc0e5018d9e6725f166afb 100644 (file)
@@ -2677,7 +2677,7 @@ rl_invoking_keyseqs_in_map (rl_command_func_t *function, Keymap map)
 {
   register int key;
   char **result;
-  int result_index, result_size;
+  size_t result_index, result_size;
 
   result = (char **)NULL;
   result_index = result_size = 0;
@@ -2874,9 +2874,9 @@ rl_dump_functions (int count, int key)
 static void
 _rl_macro_dumper_internal (int print_readably, Keymap map, char *prefix)
 {
-  register int key;
+  int key;
   char *keyname, *out;
-  int prefix_len;
+  size_t prefix_len;
 
   for (key = 0; key < KEYMAP_SIZE; key++)
     {
index 72a42696e08113879b400a5f660640fe4f0a6629..c8f96e6f64c76fb7ae2ac926c3e790778cea6087 100644 (file)
@@ -2206,7 +2206,7 @@ rl_completion_matches (const char *text, rl_compentry_func_t *entry_function)
   register int i;
 
   /* Number of slots in match_list. */
-  int match_list_size;
+  size_t match_list_size;
 
   /* The list of matches. */
   char **match_list;
index 02b5e5ccf3a80ebb7826fea4ba20c016b2b31c17..1ebb2eb5f19435897bab993bb495ef2799ba80bb 100644 (file)
@@ -664,8 +664,8 @@ rl_expand_prompt (char *prompt)
 static void
 realloc_line (int minsize)
 {
-  int minimum_size;
-  int newsize, delta;
+  size_t minimum_size;
+  size_t newsize, delta;
 
   minimum_size = DEFAULT_LINE_BUFFER_SIZE;
   if (minsize < minimum_size)
@@ -809,7 +809,7 @@ rl_redisplay (void)
 {
   int in, out, c, linenum, cursor_linenum;
   int inv_botlin, lb_botlin, lb_linenum, o_cpos;
-  int newlines, lpos, temp, n0, num, prompt_lines_estimate;
+  int newlines, lpos, temp, num, prompt_lines_estimate;
   char *prompt_this_line;
   char cur_face;
   int hl_begin, hl_end;
index 8b1cb4028db7fb0afe1e677d08d2a0ee12cac007..0095c6bfafb7905bd6b285f77939ca4e75e48fc3 100644 (file)
@@ -49,7 +49,7 @@ typedef int QSFUNC ();
 extern int _rl_qsort_string_compare (char **, char **);
 
 FUNMAP **funmap;
-static int funmap_size;
+static size_t funmap_size;
 static int funmap_entry;
 
 /* After initializing the function map, this is the index of the first
@@ -251,7 +251,7 @@ const char **
 rl_funmap_names (void)
 {
   const char **result;
-  int result_size, result_index;
+  size_t result_size, result_index;
 
   /* Make sure that the function map has been initialized. */
   rl_initialize_funmap ();
index 531e20957124040e5d21730e5319422ba045f82f..d299b5e0f0998d4679d990a1d295f5ceed6cb40b 100644 (file)
@@ -528,6 +528,8 @@ history_truncate_file (const char *fname, int lines)
   file = filename ? open (filename, O_RDONLY|O_BINARY, 0666) : -1;
   rv = exists = 0;
 
+  orig_lines = lines;
+
   /* Don't try to truncate non-regular files. */
   if (file == -1 || fstat (file, &finfo) == -1)
     {
@@ -585,7 +587,6 @@ history_truncate_file (const char *fname, int lines)
       goto truncate_exit;
     }
 
-  orig_lines = lines;
   /* Count backwards from the end of buffer until we have passed
      LINES lines.  bp1 is set funny initially.  But since bp[1] can't
      be a comment character (since it's off the end) and *bp can't be
index 17751e77dd4ec330532473baf1bf7533731e6b2e..375618174f958bb5dbbc08f9efc00836138a2284 100644 (file)
@@ -150,7 +150,7 @@ static void
 rl_display_search (char *search_string, int flags, int where)
 {
   char *message;
-  int msglen, searchlen;
+  size_t msglen, searchlen;
 
   searchlen = (search_string && *search_string) ? strlen (search_string) : 0;
 
index 41164dc26ceb2fee2c2dcf63f25e5cec58c1eb56..96523c731dc360afa25581dfbada94a1571e8d27 100644 (file)
@@ -102,7 +102,7 @@ static int vi_replace_count;
    us implicitly into insert mode.  Some people want this text to be
    attached to the command so that it is `redoable' with `.'. */
 static char *vi_insert_buffer;
-static int vi_insert_buffer_size;
+static size_t vi_insert_buffer_size;
 
 static int _rl_vi_last_repeat = 1;
 static int _rl_vi_last_arg_sign = 1;
index 0e78ad58d1af60af3a56e3b43516f6cd9a7578a3..39288ed2462da4cca4f8086ed5eda3d0db45df96 100644 (file)
@@ -48,7 +48,7 @@ extern int errno;
 
 extern char *get_working_directory (char *);
 
-static inline int
+static inline ssize_t
 _path_readlink (char *path, char *buf, size_t bufsiz)
 {
 #ifdef HAVE_READLINK
@@ -74,6 +74,7 @@ sh_physpath (char *path, int flags)
   char tbuf[PATH_MAX+1], linkbuf[PATH_MAX+1];
   char *result, *p, *q, *qsave, *qbase, *workpath;
   int double_slash_path, nlink;
+  ssize_t r;
   size_t linklen;
 
   linklen = strlen (path);
@@ -160,13 +161,14 @@ sh_physpath (char *path, int flags)
 
          *q = '\0';
 
-         linklen = _path_readlink (result, linkbuf, PATH_MAX);
-         if (linklen < 0)      /* if errno == EINVAL, it's not a symlink */
+         r = _path_readlink (result, linkbuf, PATH_MAX);
+         if (r < 0)    /* if errno == EINVAL, it's not a symlink */
            {
              if (errno != EINVAL)
                goto error;
              continue;
            }
+         linklen = r;
 
          /* It's a symlink, and the value is in LINKBUF. */
          nlink++;
index 4617932ea0066777a386a7e45d6b21772acc6f67..a27b9202833d0168c2d419067fdf39eb27c1fe4b 100644 (file)
@@ -255,18 +255,19 @@ sh_un_double_quote (char *string)
    other shell blank characters. */
    
 char *
-sh_backslash_quote (char *string, char *table, int flags)
+sh_backslash_quote (char *string, const char *table, int flags)
 {
   int c, mb_cur_max;
   size_t slen;
-  char *result, *r, *s, *backslash_table, *send;
+  char *result, *r, *s, *send;
+  const char *backslash_table;
   DECLARE_MBSTATE;
 
   slen = strlen (string);
   send = string + slen;
   result = (char *)xmalloc (2 * slen + 1);
 
-  backslash_table = table ? table : (char *)bstab;
+  backslash_table = table ? table : bstab;
   mb_cur_max = MB_CUR_MAX;
 
   for (r = result, s = string; s && (c = *s); s++)
index 9738ef464e7643506a65d3efab40325a6a52be1c..2e71fe5dda43f788eb90fe4365b7b84c26317bb3 100644 (file)
@@ -130,8 +130,8 @@ strvec_search (char **array, const char *name)
 char **
 strvec_copy (char * const *array)
 {
-  register int i;
-  int len;
+  int i;
+  size_t len;
   char **ret;
 
   len = strvec_len (array);
index 0cb66ed0a804ff55a616b2fd45aac6d11a243717..daff6a5f080e11f977236a39c79238cfcd8bae3d 100644 (file)
@@ -48,7 +48,7 @@
    quote CTLESC and CTLNUL with CTLESC.  If (flags&4) is non-zero, we want
    to remove the backslash before any unrecognized escape sequence. */
 char *
-ansicstr (const char *string, int len, int flags, int *sawc, int *rlen)
+ansicstr (const char *string, size_t len, int flags, int *sawc, size_t *rlen)
 {
   int c, temp;
   char *ret, *r;
@@ -370,10 +370,11 @@ ansic_shouldquote (const char *string)
 /* $'...' ANSI-C expand the portion of STRING between START and END and
    return the result.  The result cannot be longer than the input string. */
 char *
-ansiexpand (const char *string, int start, int end, int *lenp)
+ansiexpand (const char *string, int start, int end, size_t *lenp)
 {
   char *temp, *t;
-  int len, tlen;
+  int len;
+  size_t tlen;
 
   temp = (char *)xmalloc (end - start + 1);
   for (tlen = 0, len = start; len < end; )
index 70e6225470d7dcc03ab00272569104e8b2c9864a..c31f921393441c5ab8063c08cb73435869a2c29a 100644 (file)
@@ -160,8 +160,9 @@ tilde_find_prefix (const char *string, int *len)
 static int
 tilde_find_suffix (const char *string)
 {
-  register int i, j, string_len;
-  register char **suffixes;
+  int i, j;
+  size_t string_len;
+  char **suffixes;
 
   suffixes = tilde_additional_suffixes;
   string_len = strlen (string);
@@ -189,7 +190,7 @@ char *
 tilde_expand (const char *string)
 {
   char *result;
-  int result_size, result_index;
+  size_t result_size, result_index;
 
   result_index = result_size = 0;
   if (result = strchr (string, '~'))
@@ -200,7 +201,7 @@ tilde_expand (const char *string)
   /* Scan through STRING expanding tildes as we come to them. */
   while (1)
     {
-      register int start, end;
+      int start, end;
       char *tilde_word, *expansion;
       int len;
 
index e4050c7390e7b1cc8adc1c7ab97a388da22efb03..eb24a51735a4ce93012038b5b9e6d76b45bf7a65 100644 (file)
--- a/locale.c
+++ b/locale.c
@@ -416,11 +416,11 @@ reset_locale_vars (void)
    is not available, the passed string is returned unchanged.  The
    length of the translated string is returned in LENP, if non-null. */
 char *
-localetrans (const char *string, int len, int *lenp)
+localetrans (const char *string, int len, size_t *lenp)
 {
   char *locale, *t;
   char *translated;
-  int tlen;
+  size_t tlen;
 
   /* Don't try to translate null strings. */
   if (string == 0 || *string == 0)
@@ -521,10 +521,11 @@ mk_msgstr (char *string, int *foundnlp)
    by the caller.  The length of the translated string is returned in LENP,
    if non-null. */
 char *
-locale_expand (const char *string, int start, int end, int lineno, int *lenp)
+locale_expand (const char *string, int start, int end, int lineno, size_t *lenp)
 {
-  int len, tlen, foundnl;
+  int tlen, foundnl;
   char *temp, *t, *t2;
+  size_t len;
 
   temp = (char *)xmalloc (end - start + 1);
   for (tlen = 0, len = start; len < end; )
diff --git a/parse.y b/parse.y
index 61183c4281407ad17f4d3f81019619078d3677f5..e430f3aac0c8d6cbecce7de19c8ce8ee2878b9a5 100644 (file)
--- a/parse.y
+++ b/parse.y
@@ -179,10 +179,10 @@ static int alias_expand_token (const char *);
 static int time_command_acceptable (void);
 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);
+static char *parse_matched_pair (int, int, int, size_t *, int);
+static char *parse_comsub (int, int, int, size_t *, int);
 #if defined (ARRAY_VARS)
-static char *parse_compound_assignment (int *);
+static char *parse_compound_assignment (size_t *);
 #endif
 #if defined (DPAREN_ARITHMETIC) || defined (ARITH_FOR_COMMAND)
 static int parse_dparen (int);
@@ -2060,7 +2060,7 @@ static char *
 read_a_line (int remove_quoted_newline)
 {
   static char *line_buffer = (char *)NULL;
-  static int buffer_size = 0;
+  static size_t buffer_size = 0;
   int indx, c, peekc, pass_next;
 
 #if defined (READLINE)
@@ -2303,7 +2303,7 @@ static int unquoted_backslash = 0;
 static int
 shell_getc (int remove_quoted_newline)
 {
-  register int i;
+  int i;
   int c, truncating, last_was_backslash;
   unsigned char uc;
 
@@ -2991,6 +2991,14 @@ static int open_brace_count;
                open_brace_count++; \
              else if (word_token_alist[i].token == '}' && open_brace_count) \
                open_brace_count--; \
+\
+             if (last_read_token == IF || last_read_token == WHILE || last_read_token == UNTIL) \
+               { \
+                 if (word_top < MAX_COMPOUND_NEST) \
+                   word_top++; \
+                 word_lineno[word_top] = line_number; \
+               } \
+\
              return (word_token_alist[i].token); \
            } \
       } \
@@ -3634,12 +3642,13 @@ static char matched_pair_error;
 
 /* QC == `"' if this construct is within double quotes */
 static char *
-parse_matched_pair (int qc, int open, int close, int *lenp, int flags)
+parse_matched_pair (int qc, int open, int close, size_t *lenp, int flags)
 {
-  int count, ch, prevch, tflags;
-  int nestlen, ttranslen, start_lineno;
+  int count, ch, prevch, tflags, start_lineno;
+  size_t nestlen, ttranslen;
   char *ret, *nestret, *ttrans;
-  int retind, retsize, rflags;
+  int rflags;
+  size_t retsize, retind;
   int dolbrace_state;
 
   dolbrace_state = (flags & P_DOLBRACE) ? DOLBRACE_PARAM : 0;
@@ -4038,12 +4047,12 @@ dump_tflags (int flags)
 /* Parse a $(...) command substitution.  This reads input from the current
    input stream. QC == `"' if this construct is within double quotes */
 static char *
-parse_comsub (int qc, int open, int close, int *lenp, int flags)
+parse_comsub (int qc, int open, int close, size_t *lenp, int flags)
 {
   int peekc, r;
   int start_lineno, local_extglob, was_extpat;
   char *ret, *tcmd;
-  int retlen;
+  size_t retlen;
   sh_parser_state_t ps;
   STRING_SAVER *saved_strings;
   COMMAND *saved_global, *parsed_command;
@@ -4469,7 +4478,7 @@ parse_arith_cmd (char **ep, int adddq)
 {
   int exp_lineno, rval, c;
   char *ttok, *tokstr;
-  int ttoklen;
+  size_t ttoklen;
 
   exp_lineno = line_number;
   ttok = parse_matched_pair (0, '(', ')', &ttoklen, P_ARITH);
@@ -4831,7 +4840,7 @@ read_token_word (int character)
   int cd;
   int result, peek_char;
   char *ttok, *ttrans;
-  int ttoklen, ttranslen;
+  size_t ttoklen, ttranslen;
   intmax_t lvalue;
 
   if (token_buffer_size < TOKEN_DEFAULT_INITIAL_SIZE)
@@ -5194,7 +5203,7 @@ got_token:
   /* Check for special case tokens. */
   result = (last_shell_getc_is_singlebyte) ? special_case_tokens (token) : -1;
   if (result >= 0)
-    return result;
+    return result;     /* don't need to set word_top in any of these cases */
 
 #if defined (ALIAS)
   /* Posix.2 does not allow reserved words to be aliased, so check for all
@@ -5655,6 +5664,7 @@ decode_prompt_string (char *string)
   time_t the_time;
   char timebuf[128];
   char *timefmt;
+  size_t tslen;
 
   result = (char *)xmalloc (result_size = PROMPT_GROWTH);
   result[result_index = 0] = 0;
@@ -5737,17 +5747,17 @@ decode_prompt_string (char *string)
              tm = localtime (&the_time);
 
              if (c == 'd')
-               n = strftime (timebuf, sizeof (timebuf), "%a %b %d", tm);
+               tslen = strftime (timebuf, sizeof (timebuf), "%a %b %d", tm);
              else if (c == 't')
-               n = strftime (timebuf, sizeof (timebuf), "%H:%M:%S", tm);
+               tslen = strftime (timebuf, sizeof (timebuf), "%H:%M:%S", tm);
              else if (c == 'T')
-               n = strftime (timebuf, sizeof (timebuf), "%I:%M:%S", tm);
+               tslen = strftime (timebuf, sizeof (timebuf), "%I:%M:%S", tm);
              else if (c == '@')
-               n = strftime (timebuf, sizeof (timebuf), "%I:%M %p", tm);
+               tslen = strftime (timebuf, sizeof (timebuf), "%I:%M %p", tm);
              else if (c == 'A')
-               n = strftime (timebuf, sizeof (timebuf), "%H:%M", tm);
+               tslen = strftime (timebuf, sizeof (timebuf), "%H:%M", tm);
 
-             if (n == 0)
+             if (tslen == 0)
                timebuf[0] = '\0';
              else
                timebuf[sizeof(timebuf) - 1] = '\0';
@@ -5773,10 +5783,10 @@ decode_prompt_string (char *string)
                  timefmt[1] = 'X';     /* locale-specific current time */
                  timefmt[2] = '\0';
                }
-             n = strftime (timebuf, sizeof (timebuf), timefmt, tm);
+             tslen = strftime (timebuf, sizeof (timebuf), timefmt, tm);
              free (timefmt);
 
-             if (n == 0)
+             if (tslen == 0)
                timebuf[0] = '\0';
              else
                timebuf[sizeof(timebuf) - 1] = '\0';
@@ -6416,7 +6426,7 @@ parse_string_to_word_list (char *s, int flags, const char *whom)
 }
 
 static char *
-parse_compound_assignment (int *retlenp)
+parse_compound_assignment (size_t *retlenp)
 {
   WORD_LIST *wl, *rl;
   int tok, orig_line_number, assignok;
index a09af58246369310dc39dcb8b8496a4cfbccbc06..8fd9d394e7ee27585f7bc401182d1c14db70618c 100644 (file)
@@ -272,7 +272,7 @@ strip_trailing (char *string, int len, int newlines_only)
 
 /* A wrapper for bcopy that can be prototyped in general.h */
 void
-xbcopy (char *s, char *d, size_t n)
+xbcopy (const void *s, void *d, size_t n)
 {
   FASTCOPY (s, d, n);
 }
diff --git a/subst.c b/subst.c
index fd8f6d37a7b1e8086bff852fca83a1e68da6fe04..02dbaf03b178c1f0218881d89db7e879420eb8dd 100644 (file)
--- a/subst.c
+++ b/subst.c
@@ -1528,7 +1528,7 @@ extract_heredoc_dolbrace_string (const char *string, int *sindex, int quoted, in
       if (c == '$' && string[i+1] == '\'')
        {
          char *ttrans;
-         int ttranslen;
+         size_t ttranslen;
 
          if ((posixly_correct || extended_quote == 0) && dolbrace_state != DOLBRACE_QUOTE && dolbrace_state != DOLBRACE_QUOTE2)
            {
@@ -1573,7 +1573,7 @@ extract_heredoc_dolbrace_string (const char *string, int *sindex, int quoted, in
       if (c == '$' && string[i+1] == '"')
        {
          char *ttrans;
-         int ttranslen;
+         size_t ttranslen;
 
          si = i + 2;
          t = string_extract_double_quoted (string, &si, flags);        /* XXX */
@@ -2015,7 +2015,7 @@ skip_matched_pair (const char *string, int start, int open, int close, int flags
 {
   int i, pass_next, backq, si, c, count, oldjmp;
   size_t slen;
-  char *temp, *ss;
+  char *temp;
   DECLARE_MBSTATE;
 
   slen = strlen (string + start) + start;
@@ -2028,7 +2028,6 @@ skip_matched_pair (const char *string, int start, int open, int close, int flags
   i = (flags & 2) ? start : start + 1;
   count = 1;
   pass_next = backq = 0;
-  ss = (char *)string;
   while (c = string[i])
     {
       if (pass_next)
@@ -2074,8 +2073,8 @@ skip_matched_pair (const char *string, int start, int open, int close, int flags
        }
       else if ((flags & 1) == 0 && (c == '\'' || c == '"'))
        {
-         i = (c == '\'') ? skip_single_quoted (ss, slen, ++i, 0)
-                         : skip_double_quoted (ss, slen, ++i, 0);
+         i = (c == '\'') ? skip_single_quoted (string, slen, ++i, 0)
+                         : skip_double_quoted (string, slen, ++i, 0);
          /* no increment, the skip functions increment past the closing quote. */
        }
       else if ((flags & 1) == 0 && c == '$' && (string[i+1] == LPAREN || string[i+1] == LBRACE))
@@ -2086,9 +2085,9 @@ skip_matched_pair (const char *string, int start, int open, int close, int flags
 
          /* XXX - extract_command_subst here? */
          if (string[i+1] == LPAREN)
-           temp = extract_delimited_string (ss, &si, "$(", "(", ")", SX_NOALLOC|SX_COMMAND); /* ) */
+           temp = extract_delimited_string (string, &si, "$(", "(", ")", SX_NOALLOC|SX_COMMAND); /* ) */
          else
-           temp = extract_dollar_brace_string (ss, &si, 0, SX_NOALLOC);
+           temp = extract_dollar_brace_string (string, &si, 0, SX_NOALLOC);
 
          CHECK_STRING_OVERRUN (i, si, slen, c);
 
@@ -4054,8 +4053,9 @@ char *
 expand_string_dollar_quote (const char *string, int flags)
 {
   size_t slen, retind, retsize;
-  int sindex, c, translen, peekc, news;
+  int sindex, c, peekc, news;
   char *ret, *trans, *t;
+  size_t translen;
   const char *send;
   DECLARE_MBSTATE;
 
@@ -6570,7 +6570,8 @@ read_comsub (int fd, int quoted, int flags, int *rflag)
 #endif
 
   istring = (char *)NULL;
-  istring_index = istring_size = bufn = tflag = 0;
+  istring_index = istring_size = tflag = 0;
+  bufn = 0;
 
   skip_ctlesc = ifs_cmap[CTLESC];
   skip_ctlnul = ifs_cmap[CTLNUL];
@@ -8232,7 +8233,7 @@ string_transform (int xc, SHELL_VAR *v, char *s)
        break;
       /* Transformations that modify the variable's value */
       case 'E':
-       t = ansiexpand (s, 0, strlen (s), (int *)0);
+       t = ansiexpand (s, 0, strlen (s), 0);
        ret = dequote_escapes (t);
        free (t);
        break;
@@ -9229,7 +9230,7 @@ chk_arithsub (const char *s, int len)
          break;
 
        case '"':
-         i = skip_double_quoted ((char *)s, len, ++i, 0);
+         i = skip_double_quoted (s, len, ++i, 0);
          break;
        }
     }