mirror of
https://https.git.savannah.gnu.org/git/bash.git
synced 2026-06-29 00:19:51 +02:00
set of portability changes from lint/asan/ubsan
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
+7
-1
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -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 ();
|
||||
|
||||
+2
-1
@@ -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;
|
||||
|
||||
|
||||
+2
-1
@@ -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;
|
||||
|
||||
+3
-3
@@ -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;
|
||||
|
||||
|
||||
+1
-1
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -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)
|
||||
|
||||
+4
-3
@@ -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)
|
||||
{
|
||||
|
||||
+3
-1
@@ -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 */
|
||||
|
||||
@@ -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);
|
||||
|
||||
+9
-9
@@ -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 */
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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')
|
||||
|
||||
@@ -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 *);
|
||||
|
||||
@@ -128,7 +128,7 @@ posix_initialize (int on)
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
size_t
|
||||
num_posix_options (void)
|
||||
{
|
||||
return ((sizeof (posix_vars) / sizeof (posix_vars[0])) - 1);
|
||||
|
||||
@@ -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 *);
|
||||
|
||||
|
||||
+3
-3
@@ -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);
|
||||
|
||||
+3
-3
@@ -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++)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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 ();
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
+5
-3
@@ -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++;
|
||||
|
||||
+4
-3
@@ -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++)
|
||||
|
||||
+2
-2
@@ -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);
|
||||
|
||||
+4
-3
@@ -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; )
|
||||
|
||||
+5
-4
@@ -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;
|
||||
|
||||
|
||||
@@ -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; )
|
||||
|
||||
@@ -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;
|
||||
|
||||
+1
-1
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user