Skip to content

Commit

Permalink
More really boring maintenance
Browse files Browse the repository at this point in the history
This fixes a selection of the compiler warnings obtained from clang
19.1.6 (Linux arm64) with the flags -Wall -Wextra -pedantic.

Loads of files:
- Remove unused function parameters where possible.
- Mark many other unused function parameters with NOT_USED to
  silence the -Wextra warnings.

src/cmd/ksh93/bltins/cd_pwd.c,
src/cmd/ksh93/sh/path.c:
- Typecast void pointers returned by stkfreeze to char* before
  adding PATH_OFFSET, because pointer arithmetic with void pointers
  is technically undefined behaviour (though widely supported in
  practice). So yes, there was a minor problem following 6465cfc
  after all.

src/cmd/ksh93/sh/waitevent.c,
src/cmd/ksh93/include/shell.h,
src/cmd/ksh93/shell.3:
- Fix overly complicated typing of sh_waitnotify to avoid
  complaints about converting between void pointers and function
  pointers; the Shwait_f type is declared everywhere, so just use
  it.
  • Loading branch information
McDutchie committed Jan 6, 2025
1 parent 7ba9a3f commit 848c181
Show file tree
Hide file tree
Showing 72 changed files with 283 additions and 133 deletions.
5 changes: 4 additions & 1 deletion src/cmd/INIT/mamake.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ static const char usage[] =
#else

#define elementsof(x) (sizeof(x)/sizeof(x[0]))
#define NOT_USED(x) do (void)(x); while(0)

/*
* For compatibility with compiler flags such as -std=c99, feature macros
Expand Down Expand Up @@ -502,7 +503,7 @@ static char *appendn(Buf_t *buf, char *str, size_t n)
{
size_t m, i;

if ((n + 1) >= (buf->end - buf->nxt))
if ((n + 1) >= (size_t)(buf->end - buf->nxt))
{
i = buf->nxt - buf->buf;
m = (((buf->end - buf->buf) + n + CHUNK + 1) / CHUNK) * CHUNK;
Expand Down Expand Up @@ -2767,6 +2768,8 @@ int main(int argc, char **argv)
Buf_t *tmp;
int c;

NOT_USED(argc);

/*
* initialize the state
*/
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/builtin/pty.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) 1992-2013 AT&T Intellectual Property *
* Copyright (c) 2020-2024 Contributors to ksh 93u+m *
* Copyright (c) 2020-2025 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -382,6 +382,8 @@ process(Sfio_t* mp, Sfio_t* lp, int delay, int timeout)
struct stat dst;
struct stat fst;

NOT_USED(lp);
NOT_USED(delay);
ip = sfstdin;
if (!fstat(sffileno(ip), &dst) && !stat("/dev/null", &fst) && dst.st_dev == fst.st_dev && dst.st_ino == fst.st_ino)
ip = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/ksh93/bltins/alarm.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-2024 Contributors to ksh 93u+m *
* Copyright (c) 2020-2025 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -230,6 +230,7 @@ int b_alarm(int argc,char *argv[],Shbltin_t *context)
int n,rflag=0;
Namval_t *np;
struct tevent *tp;
NOT_USED(context);
while (n = optget(argv, sh_optalarm)) switch (n)
{
case 'r':
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/bltins/cd_pwd.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ int b_cd(int argc, char *argv[],Shbltin_t *context)
}
stkseek(sh.stk,dir-stkptr(sh.stk,0));
}
dir = stkfreeze(sh.stk,1)+PATH_OFFSET;
dir = (char*)stkfreeze(sh.stk,1) + PATH_OFFSET;
if(*dp && (*dp!='.'||dp[1]) && strchr(dir,'/'))
sfputr(sfstdout,dir,'\n');
nv_putval(opwdnod,oldpwd,NV_RDONLY);
Expand Down
6 changes: 5 additions & 1 deletion src/cmd/ksh93/bltins/enum.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-2024 Contributors to ksh 93u+m *
* Copyright (c) 2020-2025 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -122,6 +122,7 @@ static int enuminfo(Opt_t* op, Sfio_t *out, const char *str, Optdisc_t *fp)
struct Enum *ep;
int n=0;
const char *v;
NOT_USED(op);
np = *(Namval_t**)(fp+1);
ep = (struct Enum*)np->nvfun;
if(!ep)
Expand Down Expand Up @@ -151,6 +152,9 @@ static int enuminfo(Opt_t* op, Sfio_t *out, const char *str, Optdisc_t *fp)
static Namfun_t *clone_enum(Namval_t* np, Namval_t *mp, int flags, Namfun_t *fp)
{
struct Enum *ep, *pp=(struct Enum*)fp;
NOT_USED(np);
NOT_USED(mp);
NOT_USED(flags);
ep = sh_newof(0,struct Enum,1,pp->nelem*sizeof(char*));
memcpy(ep,pp,sizeof(struct Enum)+pp->nelem*sizeof(char*));
return &ep->hdr;
Expand Down
6 changes: 5 additions & 1 deletion src/cmd/ksh93/bltins/getopts.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-2024 Contributors to ksh 93u+m *
* Copyright (c) 2020-2025 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -34,6 +34,8 @@
static int infof(Opt_t* op, Sfio_t* sp, const char* s, Optdisc_t* dp)
{
Stk_t *stkp = sh.stk;
NOT_USED(op);
NOT_USED(dp);
#if SHOPT_NAMESPACE
if((sh.namespace && sh_fsearch(s,0)) || nv_search(s,sh.fun_tree,0))
#else
Expand Down Expand Up @@ -61,6 +63,8 @@ int b_getopts(int argc,char *argv[],Shbltin_t *context)
volatile int extended, r= -1;
struct checkpt buff, *pp;
Optdisc_t disc;

NOT_USED(context);
memset(&disc, 0, sizeof(disc));
disc.version = OPT_VERSION;
disc.infof = infof;
Expand Down
6 changes: 5 additions & 1 deletion 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-2024 Contributors to ksh 93u+m *
* Copyright (c) 2020-2025 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -153,6 +153,9 @@ static int infof(Opt_t* op, Sfio_t* sp, const char* s, Optdisc_t* dp)
{
const struct printmap *pm;
char c='%';
NOT_USED(op);
NOT_USED(s);
NOT_USED(dp);
for(pm=Pmap;pm->size>0;pm++)
sfprintf(sp, "[+%c(%s)q?Equivalent to %s.]",c,pm->name,pm->equivalent);
return 1;
Expand Down Expand Up @@ -750,6 +753,7 @@ static int extend(Sfio_t* sp, void* v, Sffmt_t* fe)
struct printf* pp = (struct printf*)fe;
char* argp = *pp->nextarg;
char *w,*s;
NOT_USED(sp);
if(fe->n_str>0 && (format=='T'||format=='Q') && varname(fe->t_str,fe->n_str) && (!argp || varname(argp,-1)))
{
if(argp)
Expand Down
3 changes: 2 additions & 1 deletion src/cmd/ksh93/bltins/test.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-2024 Contributors to ksh 93u+m *
* Copyright (c) 2020-2025 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -134,6 +134,7 @@ int b_test(int argc, char *argv[],Shbltin_t *context)
int not;
int exitval;

NOT_USED(context);
tdata.av = argv;
tdata.ap = 1;
if(c_eq(cp,'['))
Expand Down
5 changes: 4 additions & 1 deletion src/cmd/ksh93/bltins/trap.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-2024 Contributors to ksh 93u+m *
* Copyright (c) 2020-2025 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -46,6 +46,7 @@ int b_trap(int argc,char *argv[],Shbltin_t *context)
char *arg = argv[1];
int sig, clear = 0, dflag = 0, pflag = 0;
NOT_USED(argc);
NOT_USED(context);
while (sig = optget(argv, sh_opttrap)) switch (sig)
{
case 'p':
Expand Down Expand Up @@ -219,6 +220,7 @@ int b_kill(int argc,char *argv[],Shbltin_t *context)
int sig=SIGTERM, flag=0, n;
int usemenu = 0;
NOT_USED(argc);
NOT_USED(context);
if(**argv == 's') /* <s>top == kill -s STOP */
{
flag |= S_FLAG;
Expand Down Expand Up @@ -301,6 +303,7 @@ int b_suspend(int argc,char *argv[],Shbltin_t *context)
{
int n;
NOT_USED(argc);
NOT_USED(context);
while((n = optget(argv, sh_optsuspend))) switch(n)
{
case ':':
Expand Down
6 changes: 5 additions & 1 deletion 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-2024 Contributors to ksh 93u+m *
* Copyright (c) 2020-2025 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -94,6 +94,7 @@ int b_readonly(int argc,char *argv[],Shbltin_t *context)
char *command = argv[0];
struct tdata tdata;
NOT_USED(argc);
NOT_USED(context);
memset(&tdata,0,sizeof(tdata));
tdata.aflag = '-';
while((flag = optget(argv,*command=='e'?sh_optexport:sh_optreadonly))) switch(flag)
Expand Down Expand Up @@ -137,6 +138,7 @@ int b_alias(int argc,char *argv[],Shbltin_t *context)
int rflag=0, xflag=0, n;
struct tdata tdata;
NOT_USED(argc);
NOT_USED(context);
memset(&tdata,0,sizeof(tdata));
troot = sh.alias_tree;
if(*argv[0]=='h')
Expand Down Expand Up @@ -1133,6 +1135,7 @@ int b_builtin(int argc,char *argv[],Shbltin_t *context)
int list = 0;
#endif
NOT_USED(argc);
NOT_USED(context);
memset(&tdata,0,sizeof(tdata));
stkp = sh.stk;
if(!sh.pathlist)
Expand Down Expand Up @@ -1260,6 +1263,7 @@ int b_builtin(int argc,char *argv[],Shbltin_t *context)
int b_set(int argc,char *argv[],Shbltin_t *context)
{
struct tdata tdata;
NOT_USED(context);
memset(&tdata,0,sizeof(tdata));
tdata.prefix=0;
if(argv[1])
Expand Down
5 changes: 4 additions & 1 deletion 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-2024 Contributors to ksh 93u+m *
* Copyright (c) 2020-2025 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -50,6 +50,9 @@ static int infof(Opt_t* op, Sfio_t* sp, const char* s, Optdisc_t* dp)
{
const Limit_t* tp;

NOT_USED(op);
NOT_USED(s);
NOT_USED(dp);
for (tp = shtab_limits; tp->option; tp++)
{
sfprintf(sp, "[%c=%d:%s?The %s", tp->option, tp - shtab_limits + 1, tp->name, tp->description);
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/ksh93/bltins/whence.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-2024 Contributors to ksh 93u+m *
* Copyright (c) 2020-2025 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -52,6 +52,7 @@ static int whence(char**, int);
int b_command(int argc,char *argv[],Shbltin_t *context)
{
int n, flags=0;
NOT_USED(context);
opt_info.index = opt_info.offset = 0;
while((n = optget(argv,sh_optcommand))) switch(n)
{
Expand Down Expand Up @@ -111,6 +112,7 @@ int b_whence(int argc,char *argv[],Shbltin_t *context)
{
int flags=0, n;
NOT_USED(argc);
NOT_USED(context);
if(*argv[0]=='t')
flags = V_FLAG; /* <t>ype == whence -v */
while((n = optget(argv,sh_optwhence))) switch(n)
Expand Down
1 change: 1 addition & 0 deletions src/cmd/ksh93/edit/edit.c
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,7 @@ int ed_read(void *context, int fd, char *buff, int size, int reedit)
int delim = ((ep->e_raw&RAWMODE)?nttyparm.c_cc[VEOL]:'\n');
int mode = -1;
int (*waitevent)(int,long,int) = sh.waitevent;
NOT_USED(reedit);
/* sfpkrd must use select(2) to intercept SIGWINCH for ed_read */
if(size < 0)
{
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/ksh93/edit/history.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-2024 Contributors to ksh 93u+m *
* Copyright (c) 2020-2025 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -152,7 +152,7 @@ static History_t *hist_ptr;
#endif /* SHOPT_ACCTFILE */

#if SHOPT_AUDIT
static int sh_checkaudit(History_t *hp, const char *name, char *logbuf, size_t len)
static int sh_checkaudit(const char *name, char *logbuf, size_t len)
{
char *cp, *last;
int id1, id2, r=0, n, fd;
Expand Down Expand Up @@ -340,7 +340,7 @@ int sh_histinit(void)
{
char buff[SFIO_BUFSIZE];
hp->auditfp = 0;
if(sh_isstate(SH_INTERACTIVE) && (hp->auditmask=sh_checkaudit(hp,SHOPT_AUDITFILE, buff, sizeof(buff))))
if(sh_isstate(SH_INTERACTIVE) && (hp->auditmask = sh_checkaudit(SHOPT_AUDITFILE, buff, sizeof(buff))))
{
if((fd=sh_open(buff,O_BINARY|O_WRONLY|O_APPEND|O_CREAT|O_cloexec,S_IRUSR|S_IWUSR))>=0 && fd < 10)
{
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/ksh93/include/jobs.h
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-2024 Contributors to ksh 93u+m *
* Copyright (c) 2020-2025 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -126,7 +126,7 @@ extern void job_subrestore(void*);
#if SHOPT_BGX
extern void job_chldtrap(int);
#endif /* SHOPT_BGX */
extern void job_init(int);
extern void job_init(void);
extern int job_close(void);
extern int job_list(struct process*,int);
extern int job_hup(struct process *, int);
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/ksh93/include/shell.h
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ extern ssize_t sh_write(int, const void*, size_t);
extern off_t sh_seek(int, off_t, int);
extern int sh_pipe(int[]);
extern mode_t sh_umask(mode_t);
extern void *sh_waitnotify(Shwait_f);
extern Shwait_f sh_waitnotify(Shwait_f);
extern Shscope_t *sh_getscope(int,int);
extern Shscope_t *sh_setscope(Shscope_t*);
extern void sh_sigcheck(void);
Expand Down
4 changes: 3 additions & 1 deletion src/cmd/ksh93/sh/args.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-2024 Contributors to ksh 93u+m *
* Copyright (c) 2020-2025 Contributors to ksh 93u+m *
* and is licensed under the *
* Eclipse Public License, Version 2.0 *
* *
Expand Down Expand Up @@ -99,6 +99,8 @@ void *sh_argopen(void)

static int infof(Opt_t* op, Sfio_t* sp, const char* s, Optdisc_t* dp)
{
NOT_USED(op);
NOT_USED(dp);
if(*s!=':')
sfputr(sp,sh_set,-1);
return 1;
Expand Down
Loading

0 comments on commit 848c181

Please sign in to comment.