1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-02-13 19:52:20 +00:00

Fix many compiler warnings and remove unused variables (#191)

Most of these changes remove unused variables, functions and labels
to fix -Wunused compiler warnings. Somewhat notable changes:

src/cmd/ksh93/bltins/print.c:
- Removed the unused 'neg' variable.
  Patch from ksh2020: https://github.com/att/ast/pull/725

src/cmd/ksh93/bltins/sleep.c:
- Initialized ns to fix three -Wsometimes-uninitialized warnings.

src/cmd/ksh93/edit/{emacs,vi}.c:
- Adjust strncpy size to fix two -Wstringop-truncation warnings.

src/cmd/ksh93/include/shell.h:
- The NOT_USED macro caused many -Wunused-value warnings,
  so it has been replaced with ksh2020's macro:
  https://github.com/att/ast/commit/19d0620a

src/cmd/ksh93/sh/expand.c:
- Removed an unnecessary 'ap = ' since 'ap' is never read
  between stakseek and stakfreeze.

src/cmd/ksh93/edit/vi.c: refresh():
- Undef this function's 'w' macro at the end of it to stop it
  potentially interfering with future code changes.

src/cmd/ksh93/sh/nvdisc.c,
src/lib/libast/misc/magic.c,
src/lib/libast/regex/regsubexec.c,
src/lib/libast/sfio/sfpool.c,
src/lib/libast/vmalloc/vmbest.c:
- Fixed some indentation to silence -Wmisleading-indentation
  warnings.

src/lib/libast/include/ast.h:
- For clang, now only suppress hundreds of -Wparentheses warnings
  as well as a few -Wstring-plus-int warnings.
  Clang's -Wparentheses warns about things like
  	if(foo = bar())
  which assigns to foo and checks the assigned value.
  Clang wants us to change this into
  	if((foo = bar()))
  Clang's -Wstring-plus-int warns about things like
  	"string"+x
  where x is an integer, e.g. "string"+3 represents the string
  "ing". Clang wants us to change that to
  	"string"[3]
  The original versions represent a perfectly valid coding style
  that was common in the 1980s and 1990s and is not going to change
  in this historic code base. (gcc does not complain about these.)

Co-authored-by: Martijn Dekker <martijn@inlv.org>
This commit is contained in:
Johnothan King 2021-02-22 14:16:32 -08:00 committed by GitHub
parent 83630f9d1c
commit 733f70e94b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
27 changed files with 64 additions and 113 deletions

View file

@ -679,7 +679,6 @@ static const char *mapformat(Sffmt_t *fe)
static int extend(Sfio_t* sp, void* v, Sffmt_t* fe)
{
char* lastchar = "";
register int neg = 0;
Sfdouble_t d;
Sfdouble_t longmin = LDBL_LLONG_MIN;
Sfdouble_t longmax = LDBL_LLONG_MAX;
@ -884,8 +883,6 @@ static int extend(Sfio_t* sp, void* v, Sffmt_t* fe)
}
break;
}
if(neg)
value->ll = -value->ll;
fe->size = sizeof(value->ll);
break;
case 'a':

View file

@ -73,6 +73,7 @@ int b_sleep(register int argc,char *argv[],Shbltin_t *context)
Time_t now,ns;
char* pp;
now = TMX_NOW;
ns = 0;
if(*cp == 'P' || *cp == 'p')
ns = tmxdate(cp, &last, now);
else if(*last=='.' && shp->decomma && d==(unsigned long)d)

View file

@ -72,12 +72,6 @@ static int setall(char**, int, Dt_t*, struct tdata*);
static void pushname(Namval_t*,void*);
static void(*nullscan)(Namval_t*,void*);
static Namval_t *load_class(const char *name)
{
errormsg(SH_DICT,ERROR_exit(1),"%s: type not loadable",name);
return(0);
}
/*
* Note export and readonly are the same
*/
@ -131,7 +125,6 @@ int b_alias(int argc,register char *argv[],Shbltin_t *context)
register Dt_t *troot;
register int rflag=0, n;
struct tdata tdata;
Namval_t *np;
NOT_USED(argc);
memset((void*)&tdata,0,sizeof(tdata));
tdata.sh = context->shp;

View file

@ -1344,7 +1344,7 @@ static void search(Emacs_t* ep,genchar *out,int direction)
#if SHOPT_MULTIBYTE
ed_external(string,(char*)string);
#endif /* SHOPT_MULTIBYTE */
strncpy(lstring,((char*)string)+2,SEARCHSIZE);
strncpy(lstring,((char*)string)+2,SEARCHSIZE-1);
lstring[SEARCHSIZE-1] = 0;
ep->prevdirection = direction;
}

View file

@ -67,12 +67,10 @@
# define iswprint(c) ((c&~0177) || isprint(c))
# endif
static int _isalph(int);
static int _ismetach(int);
static int _isblank(int);
# undef isblank
# define isblank(v) _isblank(virtual[v])
# define isalph(v) _isalph(virtual[v])
# define ismetach(v) _ismetach(virtual[v])
#else
static genchar _c;
# define gencpy(a,b) strcpy((char*)(a),(char*)(b))
@ -81,7 +79,6 @@
# define isalph(v) ((_c=virtual[v])=='_'||isalnum(_c))
# undef isblank
# define isblank(v) isspace(virtual[v])
# define ismetach(v) ismeta(virtual[v])
# define digit(c) isdigit(c)
# define is_print(c) isprint(c)
#endif /* SHOPT_MULTIBYTE */
@ -2098,6 +2095,7 @@ static void refresh(register Vi_t* vp, int mode)
cursor(vp,ncur_phys);
ed_flush(vp->ed);
return;
# undef w
}
/*{ REPLACE( char, increment )
@ -2323,7 +2321,7 @@ static int search(register Vi_t* vp,register int mode)
location = hist_find(shgd->hist_ptr,((char*)virtual)+1, curhline, 1, new_direction);
}
cur_virt = i;
strncpy(lsearch, ((char*)virtual)+1, SEARCHSIZE);
strncpy(lsearch, ((char*)virtual)+1, SEARCHSIZE-1);
lsearch[SEARCHSIZE-1] = 0;
if( (curhline=location.hist_command) >=0 )
{
@ -2785,12 +2783,6 @@ yankeol:
{
return((v&~STRIP)==0 && isspace(v));
}
static int _ismetach(register int v)
{
return((v&~STRIP)==0 && ismeta(v));
}
#endif /* SHOPT_MULTIBYTE */
/*

View file

@ -122,6 +122,7 @@ eval `iffe $iffeflags -c "$cc" - num $nums $iffehdrs $iffelibs 2>&$stderr`
cat <<!
#pragma prototyped
#pragma clang diagnostic ignored "-Wdeprecated-declarations"
/* : : generated by $command from $table : : */

View file

@ -37,8 +37,17 @@
# include <nval.h>
#endif /* _SH_PRIVATE */
/*
* This is a macro that can be used to silence "unused parameter" warnings from the compiler for
* functions which need to accept parameters they do not use because they need to be compatible
* with an interface.
*/
#undef NOT_USED
#define NOT_USED(x) (&x,1)
#define NOT_USED(expr) \
do { \
(void)(expr); \
} while (0)
/* options */
typedef struct

View file

@ -65,11 +65,6 @@
# define GLOB_AUGMENTED 0
#endif
#define GLOB_RESCAN 1
#define globptr() ((struct glob*)membase)
static struct glob *membase;
static char *nextdir(glob_t *gp, char *dir)
{
Shell_t *shp = sh_getinterp();
@ -143,7 +138,7 @@ static int scantree(Dt_t *tree, const char *pattern, struct argnod **arghead)
{
if(strmatch(cp=nv_name(np),pattern))
{
ap = (struct argnod*)stakseek(ARGVAL);
(void)stakseek(ARGVAL);
stakputs(cp);
ap = (struct argnod*)stakfreeze(1);
ap->argbegin = NIL(char*);

View file

@ -383,16 +383,6 @@ static void put_cdpath(register Namval_t* np,const char *val,int flags,Namfun_t
}
#ifdef _hdr_locale
/*
* This function needs to be modified to handle international
* error message translations
*/
static char* msg_translate(const char* catalog, const char* message)
{
NOT_USED(catalog);
return((char*)message);
}
/* Trap for LC_ALL, LC_CTYPE, LC_MESSAGES, LC_COLLATE and LANG */
static void put_lang(Namval_t* np,const char *val,int flags,Namfun_t *fp)
{
@ -731,13 +721,6 @@ static void put_lastarg(Namval_t* np,const char *val,int flags,Namfun_t *fp)
np->nvenv = 0;
}
static int hasgetdisc(register Namfun_t *fp)
{
while(fp && !fp->disc->getnum && !fp->disc->getval)
fp = fp->next;
return(fp!=0);
}
/*
* store the most recent value for use in .sh.match
* treat .sh.match as a two dimensional array
@ -1034,7 +1017,6 @@ static const Namdisc_t SH_MATH_disc = { 0, 0, get_math, 0, setdisc_any, create_
return((char*)np->nvalue.cp);
}
static const Namdisc_t NSPACE_disc = { 0, 0, get_nspace };
static Namfun_t NSPACE_init = { &NSPACE_disc, 1};
#endif /* SHOPT_NAMESPACE */
#ifdef _hdr_locale

View file

@ -387,14 +387,6 @@ struct Match
char *base;
};
static int matchf(void *handle, char *ptr, size_t size)
{
struct Match *mp = (struct Match*)handle;
mp->offset += (ptr-mp->base);
return(1);
}
static struct fdsave *filemap;
static short filemapsize;

View file

@ -1092,8 +1092,6 @@ int job_kill(register struct process *pw,register int sig)
int job_hup(struct process *pw, int sig)
{
struct process *px;
pid_t pid;
int r;
NOT_USED(sig);
if(pw->p_pgrp == 0 || (pw->p_flag & P_DISOWN))
return(0);

View file

@ -70,7 +70,6 @@ static void coproc_init(Shell_t*, int pipes[]);
static void *timeout;
static char nlock;
static char pipejob;
static char nopost;
static int restorefd;
struct funenv

View file

@ -203,7 +203,7 @@ int type;
goto do_insert;
}
else if(type&(DT_INSERT|DT_INSTALL|DT_APPEND|DT_ATTACH))
{ dt_insert:
{
if(!(r = _dtmake(dt, obj, type)) )
DTRETURN(obj, NIL(Void_t*));
dt->data->size += 1;

View file

@ -1195,7 +1195,7 @@ printf("#endif\n");
*:U*) cat >> $tmp.l <<!
printf("#ifndef ${conf_name}\n");
printf("#ifndef ${x}\n");
printf("#define ${x} %lu\n", ${x});
printf("#define ${x} %lu\n", (unsigned long)${x});
printf("#endif\n");
printf("#define ${conf_name} ${x}\n");
printf("#endif\n");
@ -1204,7 +1204,7 @@ printf("#endif\n");
*:$sym) cat >> $tmp.l <<!
printf("#ifndef ${conf_name}\n");
printf("#ifndef ${x}\n");
printf("#define ${x} %ld\n", ${x});
printf("#define ${x} %ld\n", (long)${x});
printf("#endif\n");
printf("#define ${conf_name} ${x}\n");
printf("#endif\n");

View file

@ -19,6 +19,7 @@
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma clang diagnostic ignored "-Wincompatible-library-redeclaration"
/*
* strtoll() implementation
*/

View file

@ -19,6 +19,7 @@
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma clang diagnostic ignored "-Wincompatible-library-redeclaration"
/*
* strtoull() implementation
*/

View file

@ -20,6 +20,7 @@
* *
***********************************************************************/
#pragma prototyped
#pragma clang diagnostic ignored "-Wparentheses"
/*
* Glenn Fowler
* AT&T Research

View file

@ -20,9 +20,8 @@
* *
***********************************************************************/
#pragma prototyped
#pragma clang diagnostic ignored "-Wmacro-redefined"
#pragma clang diagnostic ignored "-Wparentheses"
#pragma clang diagnostic ignored "-Wunused-value"
#pragma clang diagnostic ignored "-Wstring-plus-int"
/*
* Advanced Software Technology Library

View file

@ -297,20 +297,6 @@ static const Attr_t attrs[] =
static const char unknown[] = C("unknown option or attribute");
static const char* heading[] =
{
C("INDEX"),
C("USER COMMANDS"),
C("SYSTEM LIBRARY"),
C("USER LIBRARY"),
C("FILE FORMATS"),
C("MISCELLANEOUS"),
C("GAMES and DEMOS"),
C("SPECIAL FILES"),
C("ADMINISTRATIVE COMMANDS"),
C("GUIs"),
};
/*
* list of common man page strings
* NOTE: add but do not delete from this table

View file

@ -19,6 +19,7 @@
* Phong Vo <kpv@research.att.com> *
* *
***********************************************************************/
#pragma clang diagnostic ignored "-Wparentheses"
/*
* generate <lc.h> implementation tables from lc.tab
* this must make it through vanilla cc with no -last

View file

@ -288,7 +288,8 @@ reg int mode;
/* f already in the same pool with pf */
if(f == pf || (pf && f->pool == pf->pool && f->pool != &_Sfpool) )
{ if(f)
{
if(f)
SFMTXUNLOCK(f);
if(pf)
SFMTXUNLOCK(pf);

View file

@ -836,7 +836,8 @@ tmxdate(register const char* s, char** e, Time_t now)
}
else
{
for (u = t; isspace(*u); u++);
for (u = t; isspace(*u); u++)
;
message((-1, "AHA#%d n=%d u=\"%s\"", __LINE__, n, u));
if ((j = tmlex(u, NiL, tm_info.format, TM_NFORM, tm_info.format + TM_SUFFIXES, TM_PARTS - TM_SUFFIXES)) >= 0 && tm_data.lex[j] == TM_PARTS)
s = u;
@ -978,7 +979,8 @@ tmxdate(register const char* s, char** e, Time_t now)
}
continue;
}
for (s = t; skip[*s]; s++);
for (s = t; skip[*s]; s++)
;
message((-1, "AHA#%d s=\"%s\"", __LINE__, s));
if (*s == ':' || *s == '.' && ((set|state) & (YEAR|MONTH|DAY|HOUR)) == (YEAR|MONTH|DAY))
{

View file

@ -883,7 +883,8 @@ int local;
CLRBITS(s);
}
else if(ISJUNK(s) )
{ if(!bestreclaim(vd,np,(int)C_INDEX(s)) )
{
if(!bestreclaim(vd,np,(int)C_INDEX(s)) )
/**/ASSERT(0); /* oops: did not see np! */
s = SIZE(np); /**/ASSERT(s%ALIGN == 0);
}

View file

@ -354,7 +354,6 @@ Vmdisc_t* disc;
#endif
{
int rv;
Void_t *base;
Mmdisc_t *mmdc = (Mmdisc_t*)disc;
if(type == VM_OPEN)