Skip to content

Commit

Permalink
Make the code -Wall compliant on gcc 12.2 & 13.2 and clang 14.0.0
Browse files Browse the repository at this point in the history
@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: #699
  • Loading branch information
McDutchie committed Jan 4, 2024
1 parent 799324b commit d2b3571
Show file tree
Hide file tree
Showing 78 changed files with 335 additions and 280 deletions.
16 changes: 13 additions & 3 deletions src/cmd/INIT/mamake.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
* *
Expand All @@ -15,7 +15,11 @@
* Johnothan King <[email protected]> *
* *
***********************************************************************/
#if __clang__
#pragma clang diagnostic ignored "-Wparentheses"
#elif __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)
#pragma GCC diagnostic ignored "-Wparentheses"
#endif

/*
* mamake -- MAM make
Expand All @@ -36,7 +40,7 @@ static const char usage[] =
"[-author?Glenn Fowler <[email protected]>]"
"[-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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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++);
Expand Down Expand Up @@ -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;
Expand Down
9 changes: 6 additions & 3 deletions src/cmd/ksh93/bltins/print.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
* *
Expand Down Expand Up @@ -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;
Expand All @@ -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':
Expand All @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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++)))
{
Expand Down Expand Up @@ -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;
Expand Down
7 changes: 3 additions & 4 deletions src/cmd/ksh93/bltins/typeset.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
* *
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/ksh93/bltins/ulimit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
* *
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/ksh93/edit/completion.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
* *
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/ksh93/edit/edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
* *
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/edit/history.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
26 changes: 4 additions & 22 deletions src/cmd/ksh93/edit/vi.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
* *
Expand Down Expand Up @@ -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*);
Expand All @@ -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; /* <ESC> or hangup */
char cntl_char=0; /* TRUE if control character present */
if(!vp)
{
ed->e_vi = vp = sh_newof(0,Vi_t,1,0);
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/ksh93/features/math.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 #
# #
Expand Down Expand Up @@ -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 "-Wdeprecated-declarations"
#endif
/* : : generated by $command from $table : : */
Expand Down
6 changes: 5 additions & 1 deletion src/cmd/ksh93/mamstate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
* *
Expand All @@ -14,7 +14,11 @@
* Martijn Dekker <[email protected]> *
* *
***********************************************************************/
#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
Expand Down
26 changes: 13 additions & 13 deletions src/cmd/ksh93/sh/deparse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
* *
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Loading

0 comments on commit d2b3571

Please sign in to comment.