From d2b3571e3c2644b517dfdcb7f47820bef5287fdb Mon Sep 17 00:00:00 2001 From: Martijn Dekker Date: Thu, 4 Jan 2024 00:09:38 +0000 Subject: [PATCH] Make the code -Wall compliant on gcc 12.2 & 13.2 and clang 14.0.0 @kloczek writes: > Just summary stats using gcc 13.x > > [tkloczko@pers-jacek SPECS]$ rpmbuild -ba ksh.spec 2>&1 | > grep -- \\[-W | sed 's/.*\[//; s/\]//' | > sort | uniq -c | sort -nr > 2034 -Wunknown-pragmas > 1226 -Wparentheses > 283 -Wmissing-braces > 179 -Wunused-value > 25 -Wchar-subscripts > 19 -Wlto-type-mismatch > 9 -Wunused-variable > 9 -Wunused-const-variable= > 2 -Waddress > 1 -Wuse-after-free > 1 -Wunused-function > 1 -Wunused-but-set-variable > 1 -Wsequence-point > 1 -Wdangling-pointer= Cause: build system uses -Wall to turn on ALL the warnings. Some users want a clean compile with -Wall, so here it is. -Wunknown-pragmas was fixed by adding preprocessor directives that hid them from inapplicable compilers. (AFAIK the standard says unknown pragmas are ignored, so this was pretty obnoxious.) -Wparentheses and -Wmissing-braces complain about perfectly valid C90 syntax, and I am not going to change it. Instead, these warnings have been disabled in src/lib/libast/features/common. On my own gcc tests I also had a lot of -Wmaybe-unitialized warnings. In most cases it was obvious from reading the code that the variables will not be used uninitialised, so those warnings are likely false positives. But a few of those did look like actual problems, and the overhead of variable initialisers is negligible, so this fixes them all. The rest of the warnings were fixed with appropriate code tweaks, too many to list here. Resolves: https://github.com/ksh93/ksh/issues/699 --- src/cmd/INIT/mamake.c | 16 ++++++++++++--- src/cmd/ksh93/bltins/print.c | 9 +++++--- src/cmd/ksh93/bltins/typeset.c | 7 +++---- src/cmd/ksh93/bltins/ulimit.c | 4 ++-- src/cmd/ksh93/edit/completion.c | 4 ++-- src/cmd/ksh93/edit/edit.c | 4 ++-- src/cmd/ksh93/edit/history.c | 2 +- src/cmd/ksh93/edit/vi.c | 26 ++++-------------------- src/cmd/ksh93/features/math.sh | 4 +++- src/cmd/ksh93/mamstate.c | 6 +++++- src/cmd/ksh93/sh/deparse.c | 26 ++++++++++++------------ src/cmd/ksh93/sh/expand.c | 8 +++++--- src/cmd/ksh93/sh/init.c | 3 ++- src/cmd/ksh93/sh/io.c | 4 ++-- src/cmd/ksh93/sh/jobs.c | 4 ++-- src/cmd/ksh93/sh/macro.c | 8 ++++---- src/cmd/ksh93/sh/name.c | 19 ++++++++--------- src/cmd/ksh93/sh/nvtype.c | 4 +--- src/cmd/ksh93/sh/parse.c | 2 +- src/cmd/ksh93/sh/path.c | 6 +++++- src/cmd/ksh93/sh/streval.c | 5 +++-- src/cmd/ksh93/tests/builtins.sh | 8 +++++++- src/lib/libast/cdt/dtopen.c | 3 +-- src/lib/libast/comp/setlocale.c | 17 ++++++++-------- src/lib/libast/comp/strptime.c | 4 ++-- src/lib/libast/comp/strtold.c | 7 ++++++- src/lib/libast/comp/strtoll.c | 8 ++++++-- src/lib/libast/comp/strtoull.c | 8 ++++++-- src/lib/libast/features/common | 7 ++++++- src/lib/libast/features/limits.c | 7 ++++++- src/lib/libast/features/signal.c | 10 +++++++-- src/lib/libast/hash/hashalloc.c | 4 +--- src/lib/libast/hash/hashfree.c | 10 ++++----- src/lib/libast/misc/fastfind.c | 10 ++++----- src/lib/libast/misc/glob.c | 4 ++-- src/lib/libast/misc/magic.c | 20 ++++++++---------- src/lib/libast/misc/mime.c | 15 +++++++------- src/lib/libast/misc/optget.c | 35 ++++++++++++++++---------------- src/lib/libast/misc/optjoin.c | 6 +++--- src/lib/libast/misc/procopen.c | 7 ++----- src/lib/libast/misc/stack.c | 4 +--- src/lib/libast/misc/state.c | 4 +--- src/lib/libast/misc/translate.c | 5 ++--- src/lib/libast/path/pathkey.c | 8 +++++++- src/lib/libast/path/pathpath.c | 6 ++++++ src/lib/libast/path/pathprobe.c | 8 +++++++- src/lib/libast/port/astconf.c | 6 ++---- src/lib/libast/port/lcgen.c | 10 ++++++--- src/lib/libast/port/mc.c | 6 +++--- src/lib/libast/regex/regcomp.c | 17 ++++++++-------- src/lib/libast/regex/regdecomp.c | 2 +- src/lib/libast/regex/regnexec.c | 10 ++++++--- src/lib/libast/regex/regsub.c | 6 ++++-- src/lib/libast/sfio/sfsetbuf.c | 14 +++++++++---- src/lib/libast/sfio/sftable.c | 8 ++++---- src/lib/libast/sfio/sfvscanf.c | 10 ++++----- src/lib/libast/tm/tminit.c | 6 +++--- src/lib/libast/tm/tmxdate.c | 22 ++++++++++---------- src/lib/libast/vmalloc/vmbest.c | 3 +++ src/lib/libcmd/chgrp.c | 6 +++--- src/lib/libcmd/chmod.c | 2 +- src/lib/libcmd/cksum.c | 4 ++-- src/lib/libcmd/comm.c | 6 +++--- src/lib/libcmd/cp.c | 11 +++++----- src/lib/libcmd/cut.c | 8 ++++---- src/lib/libcmd/expr.c | 2 +- src/lib/libcmd/getconf.c | 9 ++++---- src/lib/libcmd/id.c | 8 ++++---- src/lib/libcmd/join.c | 4 ++-- src/lib/libcmd/mkdir.c | 4 ++-- src/lib/libcmd/paste.c | 4 ++-- src/lib/libcmd/uniq.c | 6 +++--- src/lib/libcmd/wclib.c | 2 +- src/lib/libdll/dlfcn.c | 4 +--- src/lib/libdll/dllscan.c | 7 +++++-- src/lib/libsum/sum-att.c | 4 ++-- src/lib/libsum/sum-crc.c | 4 ++-- src/lib/libsum/sumlib.c | 4 +--- 78 files changed, 335 insertions(+), 280 deletions(-) diff --git a/src/cmd/INIT/mamake.c b/src/cmd/INIT/mamake.c index a63edf88a8af..b990812f4d08 100644 --- a/src/cmd/INIT/mamake.c +++ b/src/cmd/INIT/mamake.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1990-2013 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -15,7 +15,11 @@ * Johnothan King * * * ***********************************************************************/ +#if __clang__ #pragma clang diagnostic ignored "-Wparentheses" +#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) +#pragma GCC diagnostic ignored "-Wparentheses" +#endif /* * mamake -- MAM make @@ -36,7 +40,7 @@ static const char usage[] = "[-author?Glenn Fowler ]" "[-author?Contributors to https://github.com/ksh93/ksh]" "[-copyright?(c) 1994-2012 AT&T Intellectual Property]" -"[-copyright?(c) 2020-2023 Contributors to ksh 93u+m]" +"[-copyright?(c) 2020-2024 Contributors to ksh 93u+m]" "[-license?https://www.eclipse.org/org/documents/epl-2.0/EPL-2.0.html]" "[+NAME?mamake - make abstract machine make]" "[+DESCRIPTION?\bmamake\b reads \amake abstract machine\a target and" @@ -589,7 +593,10 @@ search(Dict_t* dict, char* name, void* value) else if (value) { if (!(root = newof(0, Dict_item_t, 1, strlen(name)))) + { report(3, "out of memory [dictionary]", name, 0); + abort(); + } strcpy(root->name, name); } if (root) @@ -727,7 +734,8 @@ view(void) } if ((s = (char*)search(state.vars, "VPATH", NULL)) && *s) { - zp = 0; + p = NULL; + zp = NULL; for (;;) { for (t = s; *t && *t != ':'; t++); @@ -770,6 +778,8 @@ view(void) } } n = strlen(s); + if(!p) + abort(); if (!(vp = newof(0, View_t, 1, strlen(p) + n + 1))) report(3, "out of memory [view]", s, 0); vp->node = n + 1; diff --git a/src/cmd/ksh93/bltins/print.c b/src/cmd/ksh93/bltins/print.c index 582c12ced644..bf8bede562bf 100644 --- a/src/cmd/ksh93/bltins/print.c +++ b/src/cmd/ksh93/bltins/print.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2014 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -178,7 +178,6 @@ int b_print(int argc, char *argv[], Shbltin_t *context) exitval = 0; disc.version = OPT_VERSION; disc.infof = infof; - opt_info.disc = &disc; if(argc>0) { options = sh_optprint; @@ -197,6 +196,7 @@ int b_print(int argc, char *argv[], Shbltin_t *context) goto skip; } } + opt_info.disc = &disc; while((n = optget(argv,options))) switch(n) { case 'n': @@ -215,6 +215,7 @@ int b_print(int argc, char *argv[], Shbltin_t *context) /* print to history file */ if(!sh_histinit()) { + opt_info.disc = NULL; errormsg(SH_DICT,ERROR_system(1),e_history); UNREACHABLE(); } @@ -251,6 +252,7 @@ int b_print(int argc, char *argv[], Shbltin_t *context) vname = nv_open(opt_info.arg, sh.var_tree, NV_VARNAME); if(!vname) { + opt_info.disc = NULL; errormsg(SH_DICT, ERROR_exit(2), e_create, opt_info.arg); UNREACHABLE(); } @@ -284,9 +286,11 @@ int b_print(int argc, char *argv[], Shbltin_t *context) errormsg(SH_DICT,2, "%s", opt_info.arg); break; case '?': + opt_info.disc = NULL; errormsg(SH_DICT,ERROR_usage(2), "%s", opt_info.arg); UNREACHABLE(); } + opt_info.disc = NULL; argv += opt_info.index; if(error_info.errors || (argc<0 && !(format = *argv++))) { @@ -1099,7 +1103,6 @@ static int extend(Sfio_t* sp, void* v, Sffmt_t* fe) */ static int reload(int argn, char fmt, void* v, Sffmt_t* fe) { - union types_t* value = (union types_t*)v; struct printf* pp = (struct printf*)fe; int r; int n; diff --git a/src/cmd/ksh93/bltins/typeset.c b/src/cmd/ksh93/bltins/typeset.c index 1c15b3a255e1..306c40fd90f4 100644 --- a/src/cmd/ksh93/bltins/typeset.c +++ b/src/cmd/ksh93/bltins/typeset.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -647,8 +647,8 @@ static int setall(char **argv,int flag,Dt_t *troot,struct tdata *tp) char *last = 0; int nvflags=(flag&(NV_ARRAY|NV_NOARRAY|NV_VARNAME|NV_IDENT|NV_ASSIGN|NV_STATIC|NV_MOVE)); int r=0, ref=0, comvar=(flag&NV_COMVAR),iarray=(flag&NV_IARRAY); - Dt_t *save_vartree; - Namval_t *save_namespace; + Dt_t *save_vartree = NULL; + Namval_t *save_namespace = NULL; if(flag&NV_GLOBAL) { save_vartree = sh.var_tree; @@ -1474,7 +1474,6 @@ static int print_namval(Sfio_t *file,Namval_t *np,int flag, struct tdata *tp) } if(isfun) { - Sfio_t *iop=0; char *fname=0; if(nv_isattr(np,NV_NOFREE)) return 0; diff --git a/src/cmd/ksh93/bltins/ulimit.c b/src/cmd/ksh93/bltins/ulimit.c index b675aaab6212..2a187b9879ed 100644 --- a/src/cmd/ksh93/bltins/ulimit.c +++ b/src/cmd/ksh93/bltins/ulimit.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -74,7 +74,7 @@ int b_ulimit(int argc,char *argv[],Shbltin_t *context) const Limit_t* tp; char* conf; int label, unit, nosupport, ret=0; - rlim_t i; + rlim_t i=0; char tmp[41]; Optdisc_t disc; NOT_USED(context); diff --git a/src/cmd/ksh93/edit/completion.c b/src/cmd/ksh93/edit/completion.c index acdc25dc47f7..a3084ff52f85 100644 --- a/src/cmd/ksh93/edit/completion.c +++ b/src/cmd/ksh93/edit/completion.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -36,7 +36,7 @@ static char *fmtx(const char *string) { const char *cp = string; - int n,c; + int n = 0, c; int pos = 0; unsigned char *state = (unsigned char*)sh_lexstates[2]; int offset = stktell(sh.stk); diff --git a/src/cmd/ksh93/edit/edit.c b/src/cmd/ksh93/edit/edit.c index ce21a8f0750d..aef41a9b1ce3 100644 --- a/src/cmd/ksh93/edit/edit.c +++ b/src/cmd/ksh93/edit/edit.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2014 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -924,7 +924,7 @@ static int putstack(Edit_t *ep,char string[], int nbyte, int type) */ int ed_getchar(Edit_t *ep,int mode) { - int n, c; + int n = 0, c; char readin[LOOKAHEAD+1]; if(!ep->e_lookahead) { diff --git a/src/cmd/ksh93/edit/history.c b/src/cmd/ksh93/edit/history.c index 5993afe5a27d..5c0b7ab2d79d 100644 --- a/src/cmd/ksh93/edit/history.c +++ b/src/cmd/ksh93/edit/history.c @@ -556,7 +556,7 @@ void hist_eof(History_t *hp) char *cp,*first,*endbuff; int incmd = 0; off_t count = hp->histcnt; - int oldind,n,skip=0; + int oldind=0,n,skip=0; off_t last = sfseek(hp->histfp,0,SEEK_END); if(last < count) { diff --git a/src/cmd/ksh93/edit/vi.c b/src/cmd/ksh93/edit/vi.c index 179f6ef2f0e6..29b315c0bcaa 100644 --- a/src/cmd/ksh93/edit/vi.c +++ b/src/cmd/ksh93/edit/vi.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -182,7 +182,6 @@ static void getline(Vi_t*,int); static int getrchar(Vi_t*); static int mvcursor(Vi_t*,int); static void pr_string(Vi_t*,const char*); -static void putstring(Vi_t*,int, int); static void refresh(Vi_t*,int); static void replace(Vi_t*,int, int); static void restore_v(Vi_t*); @@ -206,17 +205,14 @@ static int textmod(Vi_t*,int,int); int ed_viread(void *context, int fd, char *shbuf, int nchar, int reedit) { Edit_t *ed = (Edit_t*)context; - int i; /* general variable */ - int term_char=0; /* read() termination character */ + int i; /* general variable */ Vi_t *vp = ed->e_vi; char prompt[PRSIZE+2]; /* prompt */ genchar Physical[2*MAXLINE]; /* physical image */ - genchar Ubuf[MAXLINE]; /* used for U command */ - genchar ubuf[MAXLINE]; /* used for u command */ + genchar Ubuf[MAXLINE]; /* used for U command */ + genchar ubuf[MAXLINE]; /* used for u command */ genchar Window[MAXLINE]; /* window image */ int Globals[9]; /* local global variables */ - int esc_or_hang=0; /* or hangup */ - char cntl_char=0; /* TRUE if control character present */ if(!vp) { ed->e_vi = vp = sh_newof(0,Vi_t,1,0); @@ -1658,20 +1654,6 @@ static void pr_string(Vi_t *vp, const char *sp) return; } -/*{ PUTSTRING( column, nchars ) - * - * Put nchars starting at column of physical into the workspace - * to be printed. - * -}*/ - -static void putstring(Vi_t *vp,int col, int nchars) -{ - while( nchars-- ) - putchar(physical[col++]); - return; -} - /*{ VI_REDRAW( ) * * Print the prompt and force a total refresh. diff --git a/src/cmd/ksh93/features/math.sh b/src/cmd/ksh93/features/math.sh index 0113f62f146b..b145994c6997 100644 --- a/src/cmd/ksh93/features/math.sh +++ b/src/cmd/ksh93/features/math.sh @@ -2,7 +2,7 @@ # # # This software is part of the ast package # # Copyright (c) 1982-2013 AT&T Intellectual Property # -# Copyright (c) 2020-2023 Contributors to ksh 93u+m # +# Copyright (c) 2020-2024 Contributors to ksh 93u+m # # and is licensed under the # # Eclipse Public License, Version 2.0 # # # @@ -122,7 +122,9 @@ eval `iffe $iffeflags -c "$cc" - dat,npt,mac $lib $iffehdrs $iffelibs 2>&$stderr eval `iffe $iffeflags -c "$cc" - num $nums $iffehdrs $iffelibs 2>&$stderr` cat < * * * ***********************************************************************/ +#if __clang__ #pragma clang diagnostic ignored "-Wparentheses" +#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) +#pragma GCC diagnostic ignored "-Wparentheses" +#endif /* * AT&T Bell Laboratories * make abstract machine file state support diff --git a/src/cmd/ksh93/sh/deparse.c b/src/cmd/ksh93/sh/deparse.c index 309d9d049ed4..a50b4fc9a512 100644 --- a/src/cmd/ksh93/sh/deparse.c +++ b/src/cmd/ksh93/sh/deparse.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -458,7 +458,7 @@ static void p_arg(const struct argnod *arg,int endchar,int opts) static void p_redirect(const struct ionod *iop) { char *cp; - int iof,iof2; + int iof, endc, endc2 = -1; for(;iop;iop=iop->ionxt) { iof=iop->iofile; @@ -505,34 +505,34 @@ static void p_redirect(const struct ionod *iop) } sfputr(outfile,cp,-1); if(iop->ionxt) - iof = ' '; + endc = ' '; else { - if((iof=end_line)=='\n') + if((endc=end_line)=='\n') begin_line = 1; } if((iof&IOLSEEK) && (iof&IOARITH)) - iof2 = iof, iof = ' '; - if((iop->iofile & IOPROCSUB) && !(iop->iofile & IOLSEEK)) + endc2 = endc, endc = ' '; + if((iof&IOPROCSUB) && !(iof&IOLSEEK)) { /* process substitution as argument to redirection */ - sfprintf(outfile," %c(", (iop->iofile & IOPUT) ? '>' : '<'); + sfprintf(outfile," %c(", (iof&IOPUT) ? '>' : '<'); begin_line = 0; p_tree((Shnode_t*)iop->ioname,PROC_SUBST); - sfputc(outfile,iof); + sfputc(outfile,endc); } else if(iop->iodelim) { - if(!(iop->iofile&IODOC)) + if(!(iof&IODOC)) sfwrite(outfile,"''",2); - sfputr(outfile,sh_fmtq(iop->iodelim),iof); + sfputr(outfile,sh_fmtq(iop->iodelim),endc); } - else if(iop->iofile&IORAW) - sfputr(outfile,sh_fmtq(iop->ioname),iof); + else if(iof&IORAW) + sfputr(outfile,sh_fmtq(iop->ioname),endc); else sfputr(outfile,iop->ioname,iof); if((iof&IOLSEEK) && (iof&IOARITH)) - sfputr(outfile, "))", iof2); + sfputr(outfile, "))", endc2); } return; } diff --git a/src/cmd/ksh93/sh/expand.c b/src/cmd/ksh93/sh/expand.c index c1d1bd27079a..10b307d9aba3 100644 --- a/src/cmd/ksh93/sh/expand.c +++ b/src/cmd/ksh93/sh/expand.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -244,10 +244,10 @@ int path_generate(struct argnod *todo, struct argnod **arghead, int musttrim) struct argnod *ap; struct argnod *top = 0; struct argnod *apin; - char *pat, *rescan; + char *pat = NULL, *rescan; char *format; char comma, range=0; - int first, last, incr, count = 0; + int first = 0, last = 0, incr = 0, count = 0; char tmp[32], end[1]; todo->argchn.ap = 0; again: @@ -384,6 +384,8 @@ int path_generate(struct argnod *todo, struct argnod **arghead, int musttrim) } endloop1: rescan = cp; + if(!pat) + abort(); cp = pat-1; *cp = 0; while(1) diff --git a/src/cmd/ksh93/sh/init.c b/src/cmd/ksh93/sh/init.c index 471bc146ec1a..de82c67460d1 100644 --- a/src/cmd/ksh93/sh/init.c +++ b/src/cmd/ksh93/sh/init.c @@ -1593,7 +1593,8 @@ int sh_reinit(char *argv[]) dtclose(sh.fun_tree); sh.fun_tree = dp; } - dtclear(sh.fun_base = sh.fun_tree); + sh.fun_base = sh.fun_tree; + dtclear(sh.fun_base); /* Re-init built-ins as per nv_init() */ free(sh.bltin_cmds); sh.bltin_tree = sh_inittree((const struct shtable2*)shtab_builtins); diff --git a/src/cmd/ksh93/sh/io.c b/src/cmd/ksh93/sh/io.c index d292481c22c6..b580871eb362 100644 --- a/src/cmd/ksh93/sh/io.c +++ b/src/cmd/ksh93/sh/io.c @@ -1122,11 +1122,11 @@ int sh_redirect(struct ionod *iop, int flag) { Sfoff_t off; char *fname; - int fd, iof; + int fd = -1, iof; const char *message = e_open; int o_mode; /* mode flag for open */ static char io_op[7]; /* used for -x trace info */ - int trunc=0, clexec=0, fn, traceon; + int trunc=0, clexec=0, fn, traceon=0; int r, indx = sh.topfd, perm= -1; char *tname=0, *after="", *trace = sh.st.trap[SH_DEBUGTRAP]; Namval_t *np=0; diff --git a/src/cmd/ksh93/sh/jobs.c b/src/cmd/ksh93/sh/jobs.c index 909999ae3d26..a09dfadccc16 100644 --- a/src/cmd/ksh93/sh/jobs.c +++ b/src/cmd/ksh93/sh/jobs.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -971,7 +971,7 @@ static struct process *job_bystring(char *ajob) int job_kill(struct process *pw,int sig) { pid_t pid; - int r; + int r = -1; const char *msg; int stopsig = (sig==SIGSTOP||sig==SIGTSTP||sig==SIGTTIN||sig==SIGTTOU); job_lock(); diff --git a/src/cmd/ksh93/sh/macro.c b/src/cmd/ksh93/sh/macro.c index ba3e24539870..5a58a5c47313 100644 --- a/src/cmd/ksh93/sh/macro.c +++ b/src/cmd/ksh93/sh/macro.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -1145,7 +1145,7 @@ static int varsub(Mac_t *mp) { int c; int type=0; /* M_xxx */ - char *v,*argp=0; + char *v = NULL, *argp = NULL; Namval_t *np = NULL; int dolg=0, mode=0; Lex_t *lp = (Lex_t*)sh.lex_context; @@ -1893,7 +1893,7 @@ static int varsub(Mac_t *mp) { int ofs_size = 0; int match[2*(MATCH_MAX+1)],index; - int nmatch, nmatch_prev, vsize_last, tsize; + int nmatch, nmatch_prev, vsize_last = 0, tsize; char *vlast = NULL, *oldv; while(1) { @@ -2893,7 +2893,7 @@ static noreturn void mac_error(void) */ static char *mac_getstring(char *pattern) { - char *cp=pattern, *rep=0, *dp; + char *cp = pattern, *rep = NULL, *dp = NULL; int c; while(c = *cp++) { diff --git a/src/cmd/ksh93/sh/name.c b/src/cmd/ksh93/sh/name.c index 60f72ae9b159..1470b66dee68 100644 --- a/src/cmd/ksh93/sh/name.c +++ b/src/cmd/ksh93/sh/name.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -233,9 +233,9 @@ void nv_setlist(struct argnod *arg,int flags, Namval_t *typ) struct Namref nr; int maketype = flags&NV_TYPE; /* make a 'typeset -T' type definition command */ struct sh_type shtp; - Dt_t *vartree, *save_vartree; + Dt_t *vartree, *save_vartree = NULL; #if SHOPT_NAMESPACE - Namval_t *save_namespace; + Namval_t *save_namespace = NULL; #endif if(flags&NV_GLOBAL) { @@ -2089,14 +2089,12 @@ static void rightjust(char *str, int size, int fill) static int ja_size(char *str,int size,int type) { - char *cp = str; - int c, n=size; - int outsize; - char *oldcp=cp; - int oldn; - wchar_t w; + char *cp = str, *oldcp = str; + int c = 0, n = size, oldn = size; while(*cp) { + int outsize; + wchar_t w; oldn = n; w = mbchar(cp); if((outsize = mbwidth(w)) <0) @@ -2176,7 +2174,6 @@ char **sh_envgen(void) { char **er; int namec; - char *cp; struct adata data; data.tp = 0; data.mapname = 0; @@ -3546,7 +3543,7 @@ char *nv_name(Namval_t *np) Namval_t *table; Namfun_t *fp; #if SHOPT_FIXEDARRAY - Namarr_t *ap; + Namarr_t *ap = NULL; #endif /* SHOPT_FIXEDARRAY */ char *cp; if(is_abuiltin(np) || is_afunction(np)) diff --git a/src/cmd/ksh93/sh/nvtype.c b/src/cmd/ksh93/sh/nvtype.c index b83a5d21dd75..2dbd976d487c 100644 --- a/src/cmd/ksh93/sh/nvtype.c +++ b/src/cmd/ksh93/sh/nvtype.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -1410,7 +1410,6 @@ int sh_outtype(Sfio_t *out) Namval_t node,*mp,*tp; Dt_t *dp; char *cp,*sp,nvtype[sizeof(NV_CLASS)]; - Sfio_t *iop=0; int n=0,indent = 0; if(cp=sh.prefix) { @@ -1488,7 +1487,6 @@ int sh_outtype(Sfio_t *out) sfprintf(out,"h '%s'",mp->nvalue.rp->help); sfprintf(out," %s\n",cp); } - iop = 0; } } if(indent) diff --git a/src/cmd/ksh93/sh/parse.c b/src/cmd/ksh93/sh/parse.c index c765818cda4d..5fe31dff5b6e 100644 --- a/src/cmd/ksh93/sh/parse.c +++ b/src/cmd/ksh93/sh/parse.c @@ -979,7 +979,7 @@ static struct argnod *assign(Lex_t *lexp, struct argnod *ap, int type) { int n; Shnode_t *t, **tp; - struct comnod *ac; + struct comnod *ac = NULL; int array=0, index=0; Namval_t *np; lexp->assignlevel++; diff --git a/src/cmd/ksh93/sh/path.c b/src/cmd/ksh93/sh/path.c index 87a0653b53bb..f5fbb2402057 100644 --- a/src/cmd/ksh93/sh/path.c +++ b/src/cmd/ksh93/sh/path.c @@ -1536,7 +1536,7 @@ Pathcomp_t *path_addpath(Pathcomp_t *first, const char *path,int type) const char *cp; Pathcomp_t *old=0; int offset = stktell(sh.stk); - char *savptr; + char *savptr = NULL; if(!path && type!=PATH_PATH) return first; if(type!=PATH_FPATH) @@ -1576,7 +1576,11 @@ Pathcomp_t *path_addpath(Pathcomp_t *first, const char *path,int type) path_delete(old); } if(offset) + { + if(!savptr) + abort(); stkset(sh.stk,savptr,offset); + } else stkseek(sh.stk,0); return first; diff --git a/src/cmd/ksh93/sh/streval.c b/src/cmd/ksh93/sh/streval.c index 82db3b65d26c..cfff4b39204b 100644 --- a/src/cmd/ksh93/sh/streval.c +++ b/src/cmd/ksh93/sh/streval.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1982-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -153,7 +153,7 @@ Sfdouble_t arith_exec(Arith_t *ep) Sfdouble_t small_stack[SMALL_STACK+1],arg[9]; const char *ptr = ""; char *lastval=0; - int lastsub; + int lastsub=0; Math_f fun; struct lval node; node.emode = ep->emode; @@ -572,6 +572,7 @@ static int expr(struct vars *vp,int precedence) lvalue.value = 0; lvalue.nargs = 0; lvalue.fun = 0; + assignop.flag = 0; /* silence gcc warning */ again: op = gettok(vp); c = 2*MAXPREC+1; diff --git a/src/cmd/ksh93/tests/builtins.sh b/src/cmd/ksh93/tests/builtins.sh index 7b616d663c1e..de64e8f7b1e0 100755 --- a/src/cmd/ksh93/tests/builtins.sh +++ b/src/cmd/ksh93/tests/builtins.sh @@ -2,7 +2,7 @@ # # # This software is part of the ast package # # Copyright (c) 1982-2012 AT&T Intellectual Property # -# Copyright (c) 2020-2023 Contributors to ksh 93u+m # +# Copyright (c) 2020-2024 Contributors to ksh 93u+m # # and is licensed under the # # Eclipse Public License, Version 2.0 # # # @@ -1609,6 +1609,12 @@ do case $bltin in fc | hist ) ((SHOPT_SCRIPTONLY)) && continue ;; esac + got=$({ "$bltin" --\?-version; } 2>&1) # the extra { } are needed for 'redirect' + [[ $got == " version "* ]] || err_exit "$bltin does not support --\\?-version (got $(printf %q "$got"))" + case $bltin in + uname | */uname ) + continue ;; + esac got=$({ "$bltin" --version; } 2>&1) # the extra { } are needed for 'redirect' [[ $got == " version "* ]] || err_exit "$bltin does not support --version (got $(printf %q "$got"))" done 3< <(builtin) diff --git a/src/lib/libast/cdt/dtopen.c b/src/lib/libast/cdt/dtopen.c index 917f1762d48a..6995515845e4 100644 --- a/src/lib/libast/cdt/dtopen.c +++ b/src/lib/libast/cdt/dtopen.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -17,7 +17,6 @@ * * ***********************************************************************/ #include "dthdr.h" -static char* Version = "\n@(#)$Id: cdt (AT&T Labs - Research) 2011-11-11 $\0\n"; /* Make a new dictionary ** diff --git a/src/lib/libast/comp/setlocale.c b/src/lib/libast/comp/setlocale.c index a0e0b450b696..7bc21cfeeab6 100644 --- a/src/lib/libast/comp/setlocale.c +++ b/src/lib/libast/comp/setlocale.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -314,7 +314,7 @@ debug_strxfrm(char* t, const char* s, size_t n) { for (q = s + 2; q < r; q++) if (t < e) - *t++ = debug_order[*q]; + *t++ = debug_order[*((unsigned char*)q)]; while (w++ < DX) if (t < e) *t++ = 1; @@ -329,9 +329,9 @@ debug_strxfrm(char* t, const char* s, size_t n) if (t) { if (t < e) - *t++ = debug_order[s[0]]; + *t++ = debug_order[((unsigned char*)s)[0]]; if (t < e) - *t++ = debug_order[s[1]]; + *t++ = debug_order[((unsigned char*)s)[1]]; if (t < e) *t++ = 1; if (t < e) @@ -346,11 +346,11 @@ debug_strxfrm(char* t, const char* s, size_t n) if (t) { if (t < e) - *t++ = debug_order[s[0]]; + *t++ = debug_order[((unsigned char*)s)[0]]; if (t < e) - *t++ = debug_order[s[1]]; + *t++ = debug_order[((unsigned char*)s)[1]]; if (t < e) - *t++ = debug_order[s[2]]; + *t++ = debug_order[((unsigned char*)s)[2]]; if (t < e) *t++ = 1; } @@ -361,7 +361,7 @@ debug_strxfrm(char* t, const char* s, size_t n) if (t) { if (t < e) - *t++ = debug_order[s[0]]; + *t++ = debug_order[((unsigned char*)s)[0]]; if (t < e) *t++ = 1; if (t < e) @@ -2684,7 +2684,6 @@ _ast_setlocale(int category, const char* locale) if (!initialized) { char* u; - char tmp[256]; /* * initialize from the environment diff --git a/src/lib/libast/comp/strptime.c b/src/lib/libast/comp/strptime.c index e9ec934375fb..dfcdfa32dc55 100644 --- a/src/lib/libast/comp/strptime.c +++ b/src/lib/libast/comp/strptime.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -59,7 +59,7 @@ strptime(const char* s, const char* format, struct tm* ts) t = tmscan(s, &e, format, &f, &t, 0); if (e == (char*)s || *f) return NULL; - tmxtm(&tm, tmxclock(&t), NULL, 0); + tmxtm(&tm, tmxsns(t,0), NULL, 0); ts->tm_sec = tm.tm_sec; ts->tm_min = tm.tm_min; ts->tm_hour = tm.tm_hour; diff --git a/src/lib/libast/comp/strtold.c b/src/lib/libast/comp/strtold.c index b2340ce41a78..f7a97e80607e 100644 --- a/src/lib/libast/comp/strtold.c +++ b/src/lib/libast/comp/strtold.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -47,4 +47,9 @@ #include +/* on macOS arm64, double == long double, causing a false-positive "incompatible library declaration" warning on clang */ +#if _ast_fltmax_double && __clang__ +#pragma clang diagnostic ignored "-Wincompatible-library-redeclaration" +#endif + #include "sfstrtof.h" diff --git a/src/lib/libast/comp/strtoll.c b/src/lib/libast/comp/strtoll.c index a02b1113e0b1..9606e3c01be4 100644 --- a/src/lib/libast/comp/strtoll.c +++ b/src/lib/libast/comp/strtoll.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -17,7 +17,6 @@ * Johnothan King * * * ***********************************************************************/ -#pragma clang diagnostic ignored "-Wincompatible-library-redeclaration" /* * strtoll() implementation */ @@ -36,4 +35,9 @@ #define S2I_number intmax_t #define S2I_unumber uintmax_t +/* on macOS arm64, long == long long, causing a false-positive "incompatible library declaration" warning on clang */ +#if _ast_intmax_long && __clang__ +#pragma clang diagnostic ignored "-Wincompatible-library-redeclaration" +#endif + #include "strtoi.h" diff --git a/src/lib/libast/comp/strtoull.c b/src/lib/libast/comp/strtoull.c index 127822409056..60a6af623c6e 100644 --- a/src/lib/libast/comp/strtoull.c +++ b/src/lib/libast/comp/strtoull.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -17,7 +17,6 @@ * Johnothan King * * * ***********************************************************************/ -#pragma clang diagnostic ignored "-Wincompatible-library-redeclaration" /* * strtoull() implementation */ @@ -37,4 +36,9 @@ #define S2I_unumber uintmax_t #define S2I_unsigned 1 +/* on macOS arm64, long == long long, causing a false-positive "incompatible library declaration" warning on clang */ +#if _ast_intmax_long && __clang__ +#pragma clang diagnostic ignored "-Wincompatible-library-redeclaration" +#endif + #include "strtoi.h" diff --git a/src/lib/libast/features/common b/src/lib/libast/features/common index 67acf2301a08..1867109615b9 100644 --- a/src/lib/libast/features/common +++ b/src/lib/libast/features/common @@ -14,11 +14,16 @@ std noreturn note{ noreturn ok }end compile{ }end cat{ + #if __clang__ + #pragma clang diagnostic ignored "-Wmissing-braces" #pragma clang diagnostic ignored "-Wparentheses" #pragma clang diagnostic ignored "-Wstring-plus-int" #pragma clang diagnostic ignored "-Wunused-value" - #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) + #elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) + #pragma GCC diagnostic ignored "-Wmissing-braces" + #pragma GCC diagnostic ignored "-Wparentheses" #pragma GCC diagnostic ignored "-Wunused-result" + #pragma GCC diagnostic ignored "-Wunused-value" #endif /* AST backward compatibility macros */ diff --git a/src/lib/libast/features/limits.c b/src/lib/libast/features/limits.c index 07051d2293c2..21696b46dc16 100644 --- a/src/lib/libast/features/limits.c +++ b/src/lib/libast/features/limits.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -17,6 +17,11 @@ * Johnothan King * * * ***********************************************************************/ +#if __clang__ +#pragma clang diagnostic ignored "-Wunused-variable" +#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) +#pragma GCC diagnostic ignored "-Wunused-variable" +#endif /* * Glenn Fowler * AT&T Research diff --git a/src/lib/libast/features/signal.c b/src/lib/libast/features/signal.c index 9340d527de7f..94ceac1a1a2e 100644 --- a/src/lib/libast/features/signal.c +++ b/src/lib/libast/features/signal.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -17,7 +17,13 @@ * Johnothan King * * * ***********************************************************************/ +#if __clang__ #pragma clang diagnostic ignored "-Wparentheses" +#pragma clang diagnostic ignored "-Wmissing-braces" +#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) +#pragma GCC diagnostic ignored "-Wparentheses" +#pragma GCC diagnostic ignored "-Wmissing-braces" +#endif /* * Glenn Fowler * AT&T Research @@ -308,6 +314,7 @@ main(void) k = j; mapindex[j] = i; } + n = 1; #ifdef SIGRTMIN i = SIGRTMIN; #ifdef SIGRTMAX @@ -322,7 +329,6 @@ main(void) if (j > k) k = j; mapindex[i] = RANGE_MIN | RANGE_RT; - n = 1; while (++i < j) mapindex[i] = RANGE_RT | n++; mapindex[j] = RANGE_MAX | RANGE_RT | n; diff --git a/src/lib/libast/hash/hashalloc.c b/src/lib/libast/hash/hashalloc.c index 32bc45e7fe95..d9fb612256e9 100644 --- a/src/lib/libast/hash/hashalloc.c +++ b/src/lib/libast/hash/hashalloc.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -23,8 +23,6 @@ * hash table library */ -static const char id_hash[] = "\n@(#)$Id: hash (AT&T Research) 1996-08-11 $\0\n"; - #include "hashlib.h" #include "FEATURE/hack" diff --git a/src/lib/libast/hash/hashfree.c b/src/lib/libast/hash/hashfree.c index 410e92a37934..5d1b79a97881 100644 --- a/src/lib/libast/hash/hashfree.c +++ b/src/lib/libast/hash/hashfree.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -35,16 +35,16 @@ Hash_table_t* hashfree(Hash_table_t* tab) { - Hash_bucket_t** sp; - Hash_bucket_t* b; - Hash_bucket_t* p; + Hash_bucket_t** sp; + Hash_bucket_t* b; + Hash_bucket_t* p; Hash_bucket_t** sx; Hash_root_t* rp; Hash_table_t* tp; Hash_free_f freevalue; Hash_free_f freebucket; Hash_region_f region; - void* handle; + void* handle = NULL; if (!tab) return NULL; if (tab->table) diff --git a/src/lib/libast/misc/fastfind.c b/src/lib/libast/misc/fastfind.c index ae03b7160b58..6b7660d62411 100644 --- a/src/lib/libast/misc/fastfind.c +++ b/src/lib/libast/misc/fastfind.c @@ -69,8 +69,6 @@ * SUCH DAMAGE. */ -static const char id[] = "\n@(#)$Id: fastfind (AT&T Research) 2002-10-02 $\0\n"; - static const char lib[] = "libast:fastfind"; #include "findlib.h" @@ -139,7 +137,7 @@ typefix(char* buf, size_t n, const char* t) Find_t* findopen(const char* file, const char* pattern, const char* type, Finddisc_t* disc) { - Find_t* fp; + Find_t* fp = NULL; char* p; char* s; char* b; @@ -677,7 +675,7 @@ findopen(const char* file, const char* pattern, const char* type, Finddisc_t* di char* findread(Find_t* fp) { - char* p; + char* p = NULL; char* q; char* s; char* b; @@ -686,7 +684,7 @@ findread(Find_t* fp) int n; int m; int ignorecase; - int t; + int t = 0; unsigned char w[4]; struct stat st; @@ -802,7 +800,7 @@ findread(Find_t* fp) if (fp->dirs) for (;;) { - if (!*fp->dirs) + if (!*fp->dirs || !p) return NULL; /* diff --git a/src/lib/libast/misc/glob.c b/src/lib/libast/misc/glob.c index 97abda06bb8e..bb9a0293e6d1 100644 --- a/src/lib/libast/misc/glob.c +++ b/src/lib/libast/misc/glob.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -598,7 +598,7 @@ _ast_glob(const char* pattern, int flags, int (*errfn)(const char*, int), glob_t globlist_t* ap; char* pat; globlist_t* top; - Stk_t* oldstak; + Stk_t* oldstak = NULL; char** argv; char** av; size_t skip; diff --git a/src/lib/libast/misc/magic.c b/src/lib/libast/misc/magic.c index 5545c5e39e76..dfc421229890 100644 --- a/src/lib/libast/misc/magic.c +++ b/src/lib/libast/misc/magic.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -27,8 +27,6 @@ * the sum of the hacks {s5,v10,planix} is _____ than the parts */ -static const char id[] = "\n@(#)$Id: magic library (AT&T Research) 2011-03-09 $\0\n"; - static const char lib[] = "libast:magic"; #include @@ -935,7 +933,7 @@ ckmagic(Magic_t* mp, const char* file, char* buf, char* end, struct stat* st, un static int ckenglish(Magic_t* mp, int pun, int badpun) { - char* s; + unsigned char* s; int vowl = 0; int freq = 0; int rare = 0; @@ -946,11 +944,11 @@ ckenglish(Magic_t* mp, int pun, int badpun) return 0; if ((mp->count['>'] + mp->count['<'] + mp->count['/']) > mp->count['E'] + mp->count['e']) return 0; - for (s = "aeiou"; *s; s++) + for (s = (unsigned char*)"aeiou"; *s; s++) vowl += mp->count[toupper(*s)] + mp->count[*s]; - for (s = "etaion"; *s; s++) + for (s = (unsigned char*)"etaion"; *s; s++) freq += mp->count[toupper(*s)] + mp->count[*s]; - for (s = "vjkqxz"; *s; s++) + for (s = (unsigned char*)"vjkqxz"; *s; s++) rare += mp->count[toupper(*s)] + mp->count[*s]; return 5 * vowl >= mp->fbsz - mp->count[' '] && freq >= 10 * rare; } @@ -974,9 +972,9 @@ cklang(Magic_t* mp, const char* file, char* buf, char* end, struct stat* st) char* t2; char* t3; int n; - int badpun; + int badpun = 0; int code; - int pun; + int pun = 0; Cctype_t flags; Info_t* ip; @@ -1057,8 +1055,6 @@ cklang(Magic_t* mp, const char* file, char* buf, char* end, struct stat* st) *b = c; b = (unsigned char*)mp->fbuf; } - badpun = 0; - pun = 0; q = 0; s = 0; t = 0; @@ -2323,7 +2319,6 @@ magicclose(Magic_t* mp) char* magictype(Magic_t* mp, Sfio_t* fp, const char* file, struct stat* st) { - off_t off; char* s; mp->flags = mp->disc->flags; @@ -2332,6 +2327,7 @@ magictype(Magic_t* mp, Sfio_t* fp, const char* file, struct stat* st) s = T("cannot stat"); else { + off_t off = 0; if (mp->fp = fp) off = sfseek(mp->fp, 0, SEEK_CUR); s = type(mp, file, st, mp->tbuf, &mp->tbuf[sizeof(mp->tbuf)-1]); diff --git a/src/lib/libast/misc/mime.c b/src/lib/libast/misc/mime.c index 6a285c9d0084..f9243921c9d0 100644 --- a/src/lib/libast/misc/mime.c +++ b/src/lib/libast/misc/mime.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -24,8 +24,6 @@ * mime/mailcap support library */ -static const char id[] = "\n@(#)$Id: mime library (AT&T Research) 2002-10-29 $\0\n"; - static const char lib[] = "libast:mime"; #include "mimelib.h" @@ -142,9 +140,9 @@ mimeset(Mime_t* mp, char* s, unsigned long flags) Att_t* att; char* t; char* v; - char* k; - char* x; - Att_t* tta; + char* k = NULL; + char* x = NULL; + Att_t* tta = NULL; int q; for (; isspace(*s); s++); @@ -225,9 +223,12 @@ mimeset(Mime_t* mp, char* s, unsigned long flags) *t++ = 0; if (!(att = newof(0, Att_t, 1, 0))) return -1; + if (!x) + abort(); x = strcopy(att->name = x, k) + 1; x = strcopy(att->value = x, v) + 1; - tta = tta->next = att; + tta->next = att; + tta = att; if (!strcasecmp(k, "test")) cap->test = att->value; } diff --git a/src/lib/libast/misc/optget.c b/src/lib/libast/misc/optget.c index 55816839366f..603046b7ade4 100644 --- a/src/lib/libast/misc/optget.c +++ b/src/lib/libast/misc/optget.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -902,13 +902,15 @@ init(char* s, Optpass_t* p) if (!state.localized) { + unsigned char *opts = (unsigned char*)OPT_FLAGS; + unsigned char *o; state.localized = 1; if (!ast.locale.serial) setlocale(LC_ALL, ""); state.xp = sfstropen(); - if (!map[OPT_FLAGS[0]]) - for (n = 0, t = OPT_FLAGS; *t; t++) - map[*t] = ++n; + if (!map[opts[0]]) + for (n = 0, o = opts; *o; o++) + map[*o] = ++n; } #if _BLD_DEBUG error(-2, "optget debug"); @@ -1584,7 +1586,7 @@ args(Sfio_t* sp, char* p, int n, int flags, int style, Sfio_t* ip, int version, char* t; char* o; char* a = 0; - char* b; + char* b = style == STYLE_nroff ? "\\ " : " "; int sep; if (flags & OPT_functions) @@ -1593,7 +1595,6 @@ args(Sfio_t* sp, char* p, int n, int flags, int style, Sfio_t* ip, int version, { sep = ' '; o = T(NULL, ID, "options"); - b = style == STYLE_nroff ? "\\ " : " "; for (;;) { t = (char*)memchr(p, '\n', n); @@ -2354,10 +2355,10 @@ opthelp(const char* oopts, const char* what) char* s; char* d; char* v; - char* cb; - char* dt; + char* cb = NULL; + char* dt = NULL; char* ov; - char* pp; + char* pp = NULL; char* rb; char* re; int f; @@ -2959,6 +2960,7 @@ opthelp(const char* oopts, const char* what) rb = re = 0; sl = 0; vl = 0; + cl = 0; if (*p == '[') { if ((c = *(p = next(p + 1, version))) == '(') @@ -4285,7 +4287,7 @@ optget(char** argv, const char* oopts) int no; int nov; int num; - int numchr; + int numchr = 0; int prefix; int version; Help_t* hp; @@ -4749,13 +4751,13 @@ optget(char** argv, const char* oopts) else if (*s == '[') { s = next(s + 1, version); + k = *(f = s); if (*s == '(') { s = nest(f = s); if (!conformance(f, s - f)) goto disable; } - k = *(f = s); if (k == '+' || k == '-') /* ignore */; else if (k == '[' || version < 1) @@ -5027,7 +5029,7 @@ optget(char** argv, const char* oopts) else if (*(f + 1) == '=') break; else - cache->flags[map[*f]] = m; + cache->flags[map[*((unsigned char*)f)]] = m; j = 0; /* * parse and cache short option equivalents, @@ -5146,7 +5148,7 @@ optget(char** argv, const char* oopts) if (*(s + 2) == '?') m |= OPT_cache_optional; } - cache->flags[map[*s]] = m; + cache->flags[map[*((unsigned char*)s)]] = m; } s++; continue; @@ -5608,9 +5610,6 @@ optstr(const char* str, const char* opts) char* s = (char*)str; Sfio_t* mp; int c; - int ql; - int qr; - int qc; int v; char* e; @@ -5672,8 +5671,10 @@ optstr(const char* str, const char* opts) } if (c == ':' || c == '=') { + int ql = 0; + int qr = 0; + int qc = 0; sfputc(mp, c); - ql = qr = 0; while (c = *++s) { if (c == '\\') diff --git a/src/lib/libast/misc/optjoin.c b/src/lib/libast/misc/optjoin.c index 87a9b7cbf4e7..faa574d44cec 100644 --- a/src/lib/libast/misc/optjoin.c +++ b/src/lib/libast/misc/optjoin.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -55,8 +55,8 @@ optjoin(char** argv, ...) int user; int last_index; int last_offset; - int err_index; - int err_offset; + int err_index = 0; + int err_offset = 0; state = optstate(&opt_info); err = rep = 0; diff --git a/src/lib/libast/misc/procopen.c b/src/lib/libast/misc/procopen.c index 444f61287a35..5cecfd22bfc4 100644 --- a/src/lib/libast/misc/procopen.c +++ b/src/lib/libast/misc/procopen.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -393,7 +393,7 @@ Proc_t* procopen(const char* cmd, char** argv, char** envv, long* modv, int flags) { Proc_t* proc = 0; - int procfd; + int procfd = -1; char** p; char** v; int i; @@ -431,9 +431,6 @@ procopen(const char* cmd, char** argv, char** envv, long* modv, int flags) goto bad; switch (flags & (PROC_READ|PROC_WRITE)) { - case 0: - procfd = -1; - break; case PROC_READ: procfd = 1; break; diff --git a/src/lib/libast/misc/stack.c b/src/lib/libast/misc/stack.c index 3609bde437d9..d7a7f847b17d 100644 --- a/src/lib/libast/misc/stack.c +++ b/src/lib/libast/misc/stack.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -20,8 +20,6 @@ * pointer stack routines */ -static const char id_stack[] = "\n@(#)$Id: stack (AT&T Bell Laboratories) 1984-05-01 $\0\n"; - #include #include diff --git a/src/lib/libast/misc/state.c b/src/lib/libast/misc/state.c index 9690c2cda219..5ed71c552273 100644 --- a/src/lib/libast/misc/state.c +++ b/src/lib/libast/misc/state.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2022 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -18,8 +18,6 @@ * * ***********************************************************************/ -static const char id[] = "\n@(#)$Id: ast (ksh 93u+m) $\0\n"; - #include #undef strcmp diff --git a/src/lib/libast/misc/translate.c b/src/lib/libast/misc/translate.c index fb22f354537a..905c6e255aee 100644 --- a/src/lib/libast/misc/translate.c +++ b/src/lib/libast/misc/translate.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -295,7 +295,7 @@ translate(const char* loc, const char* cmd, const char* cat, const char* msg) char* t; int p; int oerrno; - Catalog_t* cp; + Catalog_t* cp = NULL; Message_t* mp; static uint32_t serial; @@ -348,7 +348,6 @@ translate(const char* loc, const char* cmd, const char* cat, const char* msg) #if DEBUG_trace > 1 sfprintf(sfstderr, "AHA#%d:%s cmd %s cat %s:%s ID %s msg `%s'\n", __LINE__, __FILE__, cmd, cat, error_info.catalog, ast.id, msg); #endif - cp = 0; goto done; } diff --git a/src/lib/libast/path/pathkey.c b/src/lib/libast/path/pathkey.c index 86eb01b2e540..d6c71a87294c 100644 --- a/src/lib/libast/path/pathkey.c +++ b/src/lib/libast/path/pathkey.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -280,5 +280,11 @@ pathkey_20100601(const char* lang, const char* tool, const char* apath, char* ke while (k > key + 8) *--k = '.'; } +/* disable false positive warning */ +#if __clang__ +#pragma clang diagnostic ignored "-Wreturn-stack-address" +#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) +#pragma GCC diagnostic ignored "-Wreturn-local-addr" +#endif return key == buf ? strdup(key) : key; } diff --git a/src/lib/libast/path/pathpath.c b/src/lib/libast/path/pathpath.c index 29dad620edb1..ff767e939021 100644 --- a/src/lib/libast/path/pathpath.c +++ b/src/lib/libast/path/pathpath.c @@ -120,5 +120,11 @@ pathpath_20100601(const char* p, const char* a, int mode, char* path, size_t siz x = !a && strchr(p, '/') ? "" : pathbin(); if (!(s = pathaccess(x, p, a, mode, path, size)) && !*x && (x = getenv("FPATH"))) s = pathaccess(x, p, a, mode, path, size); +/* disable false positive warning */ +#if __clang__ +#pragma clang diagnostic ignored "-Wreturn-stack-address" +#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) +#pragma GCC diagnostic ignored "-Wreturn-local-addr" +#endif return (s && path == buf) ? strdup(s) : s; } diff --git a/src/lib/libast/path/pathprobe.c b/src/lib/libast/path/pathprobe.c index 3301aee933d7..5e2fbca26ce6 100644 --- a/src/lib/libast/path/pathprobe.c +++ b/src/lib/libast/path/pathprobe.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -318,5 +318,11 @@ pathprobe_20100601(const char* lang, const char* tool, const char* aproc, int op if (eaccess(path, R_OK)) return NULL; } +/* disable false positive warning */ +#if __clang__ +#pragma clang diagnostic ignored "-Wreturn-stack-address" +#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) +#pragma GCC diagnostic ignored "-Wreturn-local-addr" +#endif return path == buf ? strdup(path) : path; } diff --git a/src/lib/libast/port/astconf.c b/src/lib/libast/port/astconf.c index b6b58027fe40..3a168e98fda8 100644 --- a/src/lib/libast/port/astconf.c +++ b/src/lib/libast/port/astconf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -23,8 +23,6 @@ * extended to allow some features to be set per-process */ -static const char id[] = "\n@(#)$Id: getconf (AT&T Research) 2012-05-01 $\0\n"; - #include "univlib.h" #include @@ -795,7 +793,7 @@ lookup(Lookup_t* look, const char* name, unsigned int flags) Conf_t* mid = (Conf_t*)conf; Conf_t* lo = mid; Conf_t* hi = mid + conf_elements; - int v; + int v = 0; int c; char* e; const Prefix_t* p; diff --git a/src/lib/libast/port/lcgen.c b/src/lib/libast/port/lcgen.c index 1c136adf9d09..c82c1c14b8a0 100644 --- a/src/lib/libast/port/lcgen.c +++ b/src/lib/libast/port/lcgen.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -17,7 +17,11 @@ * Johnothan King * * * ***********************************************************************/ +#if __clang__ #pragma clang diagnostic ignored "-Wparentheses" +#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) +#pragma GCC diagnostic ignored "-Wparentheses" +#endif /* * generate implementation tables from lc.tab * this must make it through vanilla cc with no -last @@ -231,12 +235,12 @@ main(int argc, char** argv) char** ve; Attribute_t* ap; Attribute_list_t* al; - Attribute_list_t* az; + Attribute_list_t* az = NULL; Charset_t* cp; Territory_t* tp; Language_t* lp; Language_list_t* ll; - Language_list_t* lz; + Language_list_t* lz = NULL; Map_t* mp; char* b; char* f; diff --git a/src/lib/libast/port/mc.c b/src/lib/libast/port/mc.c index eb9ac58699d6..7ab34f10bc9e 100644 --- a/src/lib/libast/port/mc.c +++ b/src/lib/libast/port/mc.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -57,7 +57,7 @@ mcfind(const char* locale, const char* catalog, int category, int nls, char* pat char* s; char* e; char* p; - const char* v; + const char* v = NULL; int i; int first; int next; @@ -622,7 +622,7 @@ mcindex(const char* s, char** e, int* set, int* msg) { SFCVINIT(); cv = _Sfcv36; - for (n = m = 0; (c = cv[*s]) < 36; s++) + for (n = m = 0; (c = cv[*((unsigned char*)s)]) < 36; s++) { m++; n ^= c; diff --git a/src/lib/libast/regex/regcomp.c b/src/lib/libast/regex/regcomp.c index f521c8de6f50..1318bebf3b39 100644 --- a/src/lib/libast/regex/regcomp.c +++ b/src/lib/libast/regex/regcomp.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2013 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -1031,7 +1031,7 @@ col(Celt_t* ce, int ic, unsigned char* bp, int bw, int bc, unsigned char* ep, in int et; Ckey_t key; - cc = 0; + c = cc = 0; for (;;) { k = key; @@ -1203,7 +1203,7 @@ bra(Cenv_t* env) * inrange: 0=no, 1=possibly, 2=definitely */ - inrange = 0; + inrange = last = 0; for (;;) { if (!(c = *env->cursor) || c == env->terminator || c == env->delimiter && (env->flags & REG_ESCAPE)) @@ -1423,10 +1423,10 @@ bra(Cenv_t* env) Cchr_t* xc; Celt_t* ce; Cchr_t key; - int rw; - int rc; + int rw = 0; + int rc = 0; wchar_t wc; - unsigned char* rp; + unsigned char* rp = NULL; unsigned char* pp; char cb[2][COLL_KEY_MAX+1]; @@ -2514,6 +2514,7 @@ grp(Cenv_t* env, int parno) } p = env->pattern; i = env->type; + e = NULL; if (x) { if (typ >= 0) @@ -2581,8 +2582,8 @@ seq(Cenv_t* env) Token_t tok; int c; int i; - int n; - int x; + int n = 1; + int x = 0; int parno; int type; regflags_t flags; diff --git a/src/lib/libast/regex/regdecomp.c b/src/lib/libast/regex/regdecomp.c index cf2316bd5ee7..d06b86a09315 100644 --- a/src/lib/libast/regex/regdecomp.c +++ b/src/lib/libast/regex/regdecomp.c @@ -71,7 +71,7 @@ decomp(Rex_t* e, Rex_t* parent, Sfio_t* sp, int type, int delimiter, regflags_t Rex_t* q; unsigned char* s; unsigned char* t; - int c; + int c = 0; int m; int cb; int cd; diff --git a/src/lib/libast/regex/regnexec.c b/src/lib/libast/regex/regnexec.c index 9bd63ae59bdb..46ec1a55f83e 100644 --- a/src/lib/libast/regex/regnexec.c +++ b/src/lib/libast/regex/regnexec.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2013 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -1032,6 +1032,8 @@ DEBUG_TEST(0x0008,(sfprintf(sfstdout, "AHA#%04d 0x%04x parse %s `%-.*s'\n", __LI cont = rex->re.conj_right.cont; break; case REX_DONE: + { + Pos_t* pos; if (!env->stack) return BEST; n = s - env->beg; @@ -1060,7 +1062,8 @@ DEBUG_TEST(0x0008,(sfprintf(sfstdout, "AHA#%04d 0x%04x parse %s `%-.*s'\n", __LI env->best[0].rm_eo = n; memcpy(&env->best[1], &env->match[1], r * sizeof(regmatch_t)); n = env->pos->cur; - if (!vector(Pos_t, env->bestpos, n)) + pos = vector(Pos_t, env->bestpos, n); + if (!pos) { env->error = REG_ESPACE; return BAD; @@ -1069,6 +1072,7 @@ DEBUG_TEST(0x0008,(sfprintf(sfstdout, "AHA#%04d 0x%04x parse %s `%-.*s'\n", __LI memcpy(env->bestpos->vec, env->pos->vec, n * sizeof(Pos_t)); DEBUG_TEST(0x0100,(sfprintf(sfstdout,"AHA#%04d 0x%04x %s (%z,%z)(%z,%z)(%z,%z)(%z,%z) (%z,%z)(%z,%z)\n", __LINE__, debug_flag, rexname(rex), env->best[0].rm_so, env->best[0].rm_eo, env->best[1].rm_so, env->best[1].rm_eo, env->best[2].rm_so, env->best[2].rm_eo, env->best[3].rm_so, env->best[3].rm_eo, env->match[0].rm_so, env->match[0].rm_eo, env->match[1].rm_so, env->match[1].rm_eo)),(0)); return GOOD; + } case REX_DOT: if (LEADING(env, rex, s)) return NONE; @@ -1854,7 +1858,7 @@ list(Env_t* env, Rex_t* rex) int regnexec_20120528(const regex_t* p, const char* s, size_t len, size_t nmatch, regmatch_t* match, regflags_t flags) { - ssize_t n; + ssize_t n = 0; int i; int j; int k; diff --git a/src/lib/libast/regex/regsub.c b/src/lib/libast/regex/regsub.c index 12e4690323b5..9ece041ab747 100644 --- a/src/lib/libast/regex/regsub.c +++ b/src/lib/libast/regex/regsub.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -33,7 +33,7 @@ subold(Sfio_t* dp, const char* op, const char* sp, size_t nmatch, regmatch_t* ma int c; char* s; char* e; - const char* b; + const char* b = NULL; regflags_t f; f = flags &= (REG_SUB_LOWER|REG_SUB_UPPER); @@ -195,6 +195,8 @@ subold(Sfio_t* dp, const char* op, const char* sp, size_t nmatch, regmatch_t* ma { if (c < 0 || *sp != ')') { + if (!b) + abort(); for (; b < sp; b++) sfputc(dp, *b); continue; diff --git a/src/lib/libast/sfio/sfsetbuf.c b/src/lib/libast/sfio/sfsetbuf.c index 69be09775866..c17dd2fa55f3 100644 --- a/src/lib/libast/sfio/sfsetbuf.c +++ b/src/lib/libast/sfio/sfsetbuf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -89,13 +89,15 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */ void* buf, /* new buffer */ size_t size) /* buffer size, -1 for default size */ { - int sf_malloc, oflags, init, okmmap, local; + int sf_malloc, oflags, init, local; ssize_t bufsize, blksz; Sfdisc_t* disc; struct stat st; uchar* obuf = NULL; ssize_t osize = 0; - +#ifdef MAP_TYPE + int okmmap; +#endif if(!f) return NULL; @@ -161,11 +163,11 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */ bufsize = 0; oflags = f->flags; +#ifdef MAP_TYPE /* see if memory mapping is possible (see sfwrite for SF_BOTH) */ okmmap = (buf || (f->flags&SF_STRING) || (f->flags&SF_RDWR) == SF_RDWR) ? 0 : 1; /* save old buffer info */ -#ifdef MAP_TYPE if(f->bits&SF_MMAP) { if(f->data) { SFMUNMAP(f,f->data,f->endb-f->data); @@ -219,16 +221,20 @@ void* sfsetbuf(Sfio_t* f, /* stream to be buffered */ f->blksz = (size_t)st.st_blksize; #endif bufsize = 64 * 1024; +#ifdef MAP_TUPE if(S_ISDIR(st.st_mode) || (Sfoff_t)st.st_size < (Sfoff_t)SF_GRAIN) okmmap = 0; +#endif if(S_ISREG(st.st_mode) || S_ISDIR(st.st_mode)) f->here = SFSK(f,0,SEEK_CUR,f->disc); else f->here = -1; +#ifdef MAP_TYPE #if O_TEXT /* no memory mapping with O_TEXT because read()/write() alter data stream */ if(okmmap && f->here >= 0 && (fcntl((int)f->file,F_GETFL,0) & O_TEXT) ) okmmap = 0; +#endif #endif } diff --git a/src/lib/libast/sfio/sftable.c b/src/lib/libast/sfio/sftable.c index 18411e115b4f..2e5a507c874a 100644 --- a/src/lib/libast/sfio/sftable.c +++ b/src/lib/libast/sfio/sftable.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -43,10 +43,10 @@ static Fmtpos_t* sffmtpos(Sfio_t* f,const char* form,va_list args,Sffmt_t* ft,in int v, n, skip, dollar, decimal, thousand; Sffmt_t savft; Fmtpos_t* fp; /* position array of arguments */ - int argp, argn, maxp, need[FP_INDEX]; + int argp, maxp, need[FP_INDEX]; int nargs; /* the argv[] index of the last seen sequential % format (% or *) */ int xargs; /* highest (max) argv[] index see in an indexed format (%x$ *x$) */ - int nextarg; + int nextarg = 0; SFMBDCL(fmbs) if(type < 0) @@ -54,7 +54,7 @@ static Fmtpos_t* sffmtpos(Sfio_t* f,const char* form,va_list args,Sffmt_t* ft,in else if(!(fp = sffmtpos(f,form,args,ft,-1)) ) return NULL; - dollar = decimal = thousand = 0; argn = maxp = -1; + dollar = decimal = thousand = 0; nargs = xargs = -1; SFMBCLR(&fmbs); while((n = *form) ) diff --git a/src/lib/libast/sfio/sfvscanf.c b/src/lib/libast/sfio/sfvscanf.c index 412dce97b4d1..2a351591cc9f 100644 --- a/src/lib/libast/sfio/sfvscanf.c +++ b/src/lib/libast/sfio/sfvscanf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -133,7 +133,7 @@ static char* _sfsetclass(const char* form, /* format string */ ac->ok[c] = !ac->yes; if(*form == ']' || *form == '-') /* special first char */ - { ac->ok[*form] = ac->yes; + { ac->ok[*((unsigned char*)form)] = ac->yes; form += 1; } ac->form = (char*)form; @@ -211,8 +211,8 @@ static int _sfgetwc(Scan_t* sc, /* the scanning handle */ Accept_t* ac, /* accept handle for %[ */ void* mbs) /* multibyte parsing state */ { - int n, v; - char b[16]; /* assuming that SFMBMAX <= 16! */ + int n, v; + unsigned char b[16]; /* assuming that SFMBMAX <= 16! */ /* shift left data so that there will be more room to back up on error. this won't help streams with small buffers - c'est la vie! */ @@ -233,7 +233,7 @@ static int _sfgetwc(Scan_t* sc, /* the scanning handle */ goto no_match; else b[n++] = v; - if(mbrtowc(wc, b, n, (mbstate_t*)mbs) == (size_t)(-1)) + if(mbrtowc(wc, (char*)b, n, (mbstate_t*)mbs) == (size_t)(-1)) goto no_match; /* malformed multi-byte char */ else { /* multi-byte char converted successfully */ diff --git a/src/lib/libast/tm/tminit.c b/src/lib/libast/tm/tminit.c index 7fef2bb8158c..9a6e359e1c63 100644 --- a/src/lib/libast/tm/tminit.c +++ b/src/lib/libast/tm/tminit.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -81,7 +81,7 @@ struct tm* _tm_localtime(const time_t* t) { struct tm* r; - char* e; + char* e = NULL; char** v = environ; if (TZ[0]) @@ -198,7 +198,7 @@ tmlocal(time_t now) Tm_zone_t* zp; int n; char* s; - char* e; + char* e = NULL; int i; int m; int isdst; diff --git a/src/lib/libast/tm/tmxdate.c b/src/lib/libast/tm/tmxdate.c index 54da45663347..29d6ec1798f4 100644 --- a/src/lib/libast/tm/tmxdate.c +++ b/src/lib/libast/tm/tmxdate.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1985-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -157,7 +157,7 @@ tmxdate(const char* s, char** e, Time_t now) { Tm_t* tm; long n; - int w; + int w = 0; unsigned long set; unsigned long state; unsigned long flags; @@ -176,7 +176,7 @@ tmxdate(const char* s, char** e, Time_t now) int f; int i; int j; - int k; + int k = 0; int l; long m; unsigned long p; @@ -252,7 +252,7 @@ tmxdate(const char* s, char** e, Time_t now) break; } } - else if (!skip[*s]) + else if (!skip[*((unsigned char*)s)]) break; s++; } @@ -815,7 +815,7 @@ tmxdate(const char* s, char** e, Time_t now) state |= ((f = n) ? NEXT : THIS)|ORDINAL; set &= ~(EXACT|LAST|NEXT|THIS); set |= state & (EXACT|LAST|NEXT|THIS); - for (s = t; skip[*s]; s++); + for (s = t; skip[*((unsigned char*)s)]; s++); if (isdigit(*s)) { if (n = strtol(s, &t, 10)) @@ -974,7 +974,7 @@ tmxdate(const char* s, char** e, Time_t now) } continue; } - for (s = t; skip[*s]; s++) + for (s = t; skip[*((unsigned char*)s)]; s++) ; message((-1, "AHA#%d s=\"%s\"", __LINE__, s)); if (*s == ':' || *s == '.' && ((set|state) & (YEAR|MONTH|DAY|HOUR)) == (YEAR|MONTH|DAY)) @@ -1086,7 +1086,7 @@ tmxdate(const char* s, char** e, Time_t now) /* +/- handled on top of loop */ if (*s == '-' || *s == '+') break; - else if (skip[*s]) + else if (skip[*((unsigned char*)s)]) s++; else break; @@ -1262,7 +1262,7 @@ tmxdate(const char* s, char** e, Time_t now) message((-1, "AHA#%d n=%d", __LINE__, n)); /* look ahead for TM_PARTS, in k used in ordinal: */ u = t; - while (skip[*u]) + while (skip[*((unsigned char*)u)]) u++; k = tmlex(u, &u, tm_info.format, TM_NFORM, @@ -1311,7 +1311,7 @@ tmxdate(const char* s, char** e, Time_t now) { /* look ahead for TM_PARTS, k used in ordinal: */ u = t; - while (skip[*u]) + while (skip[*((unsigned char*)u)]) u++; k = tmlex(u, &u, tm_info.format, TM_NFORM, @@ -1326,7 +1326,7 @@ tmxdate(const char* s, char** e, Time_t now) for (;;) { - while (skip[*s]) + while (skip[*((unsigned char*)s)]) s++; if ((k = tmlex(s, &t, tm_info.format + TM_LAST, TM_NOISE - TM_LAST, NULL, 0)) >= 0) { @@ -1536,7 +1536,7 @@ tmxdate(const char* s, char** e, Time_t now) tm->tm_mon = j - TM_MONTH; if (n < 0) { - while (skip[*s]) + while (skip[*((unsigned char*)s)]) s++; if (isdigit(*s)) { diff --git a/src/lib/libast/vmalloc/vmbest.c b/src/lib/libast/vmalloc/vmbest.c index cab0d6344946..61ee5414e367 100644 --- a/src/lib/libast/vmalloc/vmbest.c +++ b/src/lib/libast/vmalloc/vmbest.c @@ -1180,6 +1180,9 @@ static void* mallocmem(void* caddr, size_t csize, size_t nsize) return malloc(nsize); else if(nsize == 0) { free(caddr); +#if !__clang__ && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) +#pragma GCC diagnostic ignored "-Wuse-after-free" +#endif return caddr; } else return NULL; diff --git a/src/lib/libcmd/chgrp.c b/src/lib/libcmd/chgrp.c index 4a567a817456..e751194c42da 100644 --- a/src/lib/libcmd/chgrp.c +++ b/src/lib/libcmd/chgrp.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -217,8 +217,8 @@ b_chgrp(int argc, char** argv, Shbltin_t* context) Dt_t* map = 0; int logical = 1; int flags; - int uid; - int gid; + int uid = -1; + int gid = -1; char* op; char* usage; char* t; diff --git a/src/lib/libcmd/chmod.c b/src/lib/libcmd/chmod.c index 6292c3c16999..f76419741517 100644 --- a/src/lib/libcmd/chmod.c +++ b/src/lib/libcmd/chmod.c @@ -144,7 +144,7 @@ extern int lchmod(const char*, mode_t); int b_chmod(int argc, char** argv, Shbltin_t* context) { - int mode; + int mode = 0; int force = 0; int flags; char* amode = 0; diff --git a/src/lib/libcmd/cksum.c b/src/lib/libcmd/cksum.c index 3412160f3879..703f923bb089 100644 --- a/src/lib/libcmd/cksum.c +++ b/src/lib/libcmd/cksum.c @@ -259,8 +259,8 @@ verify(State_t* state, char* s, char* check, Sfio_t* rp) char* file; int attr; int mode; - int uid; - int gid; + int uid = -1; + int gid = -1; Sfio_t* sp; struct stat st; diff --git a/src/lib/libcmd/comm.c b/src/lib/libcmd/comm.c index bdf28fd3b642..084b626270a2 100644 --- a/src/lib/libcmd/comm.c +++ b/src/lib/libcmd/comm.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -63,7 +63,7 @@ static const char usage[] = static int comm(Sfio_t *in1, Sfio_t *in2, Sfio_t *out,int mode) { char *cp1, *cp2; - int n1, n2, n, comp; + int n1 = 0, n2 = 0, n, comp; if(cp1 = sfgetr(in1,'\n',0)) n1 = sfvalue(in1); if(cp2 = sfgetr(in2,'\n',0)) @@ -138,7 +138,7 @@ static int comm(Sfio_t *in1, Sfio_t *in2, Sfio_t *out,int mode) return 0; n1 = sfvalue(in1); } - /* NOT REACHED */ + UNREACHABLE(); } int diff --git a/src/lib/libcmd/cp.c b/src/lib/libcmd/cp.c index c55a8a9cdb3d..f3cf2974cb8f 100644 --- a/src/lib/libcmd/cp.c +++ b/src/lib/libcmd/cp.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -232,9 +232,7 @@ visit(State_t* state, FTSENT* ent) char* base; int n; int len; - int rm; - int rfd; - int wfd; + int rm = state->remove || ent->fts_info == FTS_SL; int m; int v; char* s; @@ -430,7 +428,6 @@ visit(State_t* state, FTSENT* ent) } if (state->verbose) sfputr(sfstdout, state->path, '\n'); - rm = state->remove || ent->fts_info == FTS_SL; if (!rm || !state->force) { if (S_ISLNK(st.st_mode) && (n = -1) || (n = open(state->path, O_RDWR|O_BINARY|O_cloexec)) >= 0) @@ -576,6 +573,8 @@ visit(State_t* state, FTSENT* ent) } else if (state->op == CP || S_ISREG(ent->fts_statp->st_mode) || S_ISDIR(ent->fts_statp->st_mode)) { + int rfd = -1; + int wfd = -1; if (ent->fts_statp->st_size > 0 && (rfd = open(ent->fts_path, O_RDONLY|O_BINARY|O_cloexec)) < 0) { error(ERROR_SYSTEM|2, "%s: cannot read", ent->fts_path); @@ -671,7 +670,7 @@ b_cp(int argc, char** argv, Shbltin_t* context) FTS* fts; FTSENT* ent; const char* usage; - int path_resolve; + int path_resolve = 0; int standard; struct stat st; State_t* state; diff --git a/src/lib/libcmd/cut.c b/src/lib/libcmd/cut.c index c1d288a868bf..ceb6e2556427 100644 --- a/src/lib/libcmd/cut.c +++ b/src/lib/libcmd/cut.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -375,12 +375,12 @@ cutfields(Cut_t* cut, Sfio_t* fdin, Sfio_t* fdout) unsigned char *sp = cut->space; unsigned char *cp; unsigned char *wp; - int c, nfields; + int c, nfields=0; const int *lp = cut->list; unsigned char *copy; - int nodelim, empty, inword=0; + int nodelim=0, empty=0, inword=0; unsigned char *ep; - unsigned char *bp, *first; + unsigned char *bp, *first=NULL; int lastchar; wchar_t w; Sfio_t *fdtmp = 0; diff --git a/src/lib/libcmd/expr.c b/src/lib/libcmd/expr.c index f6db0cd58a08..fc2233292461 100644 --- a/src/lib/libcmd/expr.c +++ b/src/lib/libcmd/expr.c @@ -434,7 +434,7 @@ static int expr_cmp(State_t* state, Node_t *np) while ((tok&~T_OP)==T_CMP) { Node_t rp; - char *left,*right; + char *left = NULL, *right = NULL; char buff1[36],buff2[36]; int op = (tok&T_OP); tok = expr_add(state, &rp); diff --git a/src/lib/libcmd/getconf.c b/src/lib/libcmd/getconf.c index 8360c2bb70cd..6f16113fd6a9 100644 --- a/src/lib/libcmd/getconf.c +++ b/src/lib/libcmd/getconf.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -131,7 +131,7 @@ int b_getconf(int argc, char** argv, Shbltin_t* context) { char* name; - char* path; + char* path = NULL; char* value; const char* s; char* pattern; @@ -208,9 +208,8 @@ b_getconf(int argc, char** argv, Shbltin_t* context) break; } argv += opt_info.index; - if (!(name = *argv)) - path = 0; - else if (streq(name, empty)) + name = *argv; + if (name && streq(name, empty)) { name = 0; if (path = *++argv) diff --git a/src/lib/libcmd/id.c b/src/lib/libcmd/id.c index 90630a94f5ac..0f381a888e99 100644 --- a/src/lib/libcmd/id.c +++ b/src/lib/libcmd/id.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -204,10 +204,10 @@ getids(Sfio_t* sp, const char* name, int flags) char* s; int lastchar; int ngroups = 0; - const char* gname; - uid_t user; + const char* gname = NULL; + uid_t user = 0; uid_t euid; - gid_t group; + gid_t group = 0; gid_t egid; static gid_t* groups; diff --git a/src/lib/libcmd/join.c b/src/lib/libcmd/join.c index 9af18b6babc2..6f71009e50d9 100644 --- a/src/lib/libcmd/join.c +++ b/src/lib/libcmd/join.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -468,7 +468,7 @@ outfield(Join_t* jp, int index, int n, int last) cpmax = fp->fields[n].end + 1; } else - cp = 0; + cp = cpmax = NULL; if ((n = jp->delim) == -1) { if (cp && fp->spaces) diff --git a/src/lib/libcmd/mkdir.c b/src/lib/libcmd/mkdir.c index 498c2503bcf3..4c9219be76ac 100644 --- a/src/lib/libcmd/mkdir.c +++ b/src/lib/libcmd/mkdir.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -70,7 +70,7 @@ b_mkdir(int argc, char** argv, Shbltin_t* context) int vflag = 0; int made; char* part; - mode_t dmode; + mode_t dmode = 0; struct stat st; cmdinit(argc, argv, context, ERROR_CATALOG, 0); diff --git a/src/lib/libcmd/paste.c b/src/lib/libcmd/paste.c index 614e92654eae..a5102cd374d6 100644 --- a/src/lib/libcmd/paste.c +++ b/src/lib/libcmd/paste.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -172,7 +172,7 @@ int b_paste(int argc, char** argv, Shbltin_t* context) { int n, sflag=0; - Sfio_t *fp, **streams; + Sfio_t *fp, **streams = NULL; char *cp, *delim; char *ep; Delim_t *mp; diff --git a/src/lib/libcmd/uniq.c b/src/lib/libcmd/uniq.c index ade8a82d5fe0..47db36d48e22 100644 --- a/src/lib/libcmd/uniq.c +++ b/src/lib/libcmd/uniq.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1992-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -82,8 +82,8 @@ typedef int (*Compare_f)(const char*, const char*, size_t); static int uniq(Sfio_t *fdin, Sfio_t *fdout, int fields, int chars, int width, int mode, int* all, Compare_f compare) { int n, f, outsize=0, mb = mbwide(); - char *cp, *ep, *mp, *bufp, *outp; - char *orecp, *sbufp=0, *outbuff; + char *cp=NULL, *ep, *mp, *bufp, *outp=NULL; + char *orecp=NULL, *sbufp=0, *outbuff; int reclen,oreclen= -1,count=0,cwidth=0,sep,next; if(mode&C_FLAG) cwidth = CWIDTH+1; diff --git a/src/lib/libcmd/wclib.c b/src/lib/libcmd/wclib.c index ae6c7d48b707..2e5669020d73 100644 --- a/src/lib/libcmd/wclib.c +++ b/src/lib/libcmd/wclib.c @@ -333,7 +333,7 @@ int wc_count(Wc_t *wp, Sfio_t *fd, const char* file) int skip=0; int adjust=0; int state=0; - int oldc; + int oldc=0; int xspace; int wasspace = 1; unsigned char* start; diff --git a/src/lib/libdll/dlfcn.c b/src/lib/libdll/dlfcn.c index 2e28c9de4ee0..eb511e611ac5 100644 --- a/src/lib/libdll/dlfcn.c +++ b/src/lib/libdll/dlfcn.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1997-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -23,8 +23,6 @@ * AT&T Research */ -static const char id[] = "\n@(#)$Id: dll library (AT&T Research) 2010-10-20 $\0\n"; - #include #include #include diff --git a/src/lib/libdll/dllscan.c b/src/lib/libdll/dllscan.c index 5439cb4f7688..2dca5fd1f280 100644 --- a/src/lib/libdll/dllscan.c +++ b/src/lib/libdll/dllscan.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1997-2012 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -103,7 +103,8 @@ dllinfo(void) s++; if (*s) { - h = 0; + h = NULL; + vn = 0; for (;;) { for (d = s; *s && *s != ':' && *s != ','; s++); @@ -145,6 +146,8 @@ dllinfo(void) } if (v && vn < sizeof(info.envbuf)) { + if(vn <= 0) + abort(); memcpy(info.envbuf, v, vn); info.env = info.envbuf; } diff --git a/src/lib/libsum/sum-att.c b/src/lib/libsum/sum-att.c index 92cde104c68b..952fc72aa4ed 100644 --- a/src/lib/libsum/sum-att.c +++ b/src/lib/libsum/sum-att.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1996-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -45,7 +45,7 @@ #endif #define CBLOCK_SIZE (64) -#if !defined(__clang__) +#if !__clang__ && !__GNUC__ #pragma unroll(16) #endif diff --git a/src/lib/libsum/sum-crc.c b/src/lib/libsum/sum-crc.c index 6b2fabbab6e9..bfdc734aeb68 100644 --- a/src/lib/libsum/sum-crc.c +++ b/src/lib/libsum/sum-crc.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1996-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -226,7 +226,7 @@ crc_init(Sum_t* p) #endif #define CBLOCK_SIZE (64) -#if !defined(__clang__) +#if !__clang__ && !__GNUC__ #pragma unroll(16) #endif diff --git a/src/lib/libsum/sumlib.c b/src/lib/libsum/sumlib.c index ecd2227fcf07..38bd7522147b 100644 --- a/src/lib/libsum/sumlib.c +++ b/src/lib/libsum/sumlib.c @@ -2,7 +2,7 @@ * * * This software is part of the ast package * * Copyright (c) 1996-2011 AT&T Intellectual Property * -* Copyright (c) 2020-2023 Contributors to ksh 93u+m * +* Copyright (c) 2020-2024 Contributors to ksh 93u+m * * and is licensed under the * * Eclipse Public License, Version 2.0 * * * @@ -22,8 +22,6 @@ * man this is sum library */ -static const char id[] = "\n@(#)$Id: sumlib (AT&T Research) 2009-09-28 $\0\n"; - #define _SUM_PRIVATE_ \ struct Method_s* method; \ uintmax_t total_count; \