1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +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:
  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

@ -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

@ -1183,24 +1183,24 @@ cklang(register Magic_t* mp, const char* file, char* buf, char* end, struct stat
mp->multi['X']++;
break;
}
if (!mp->idtab)
{
if (mp->idtab = dtnew(mp->vm, &mp->dtdisc, Dtset))
for (q = 0; q < elementsof(dict); q++)
dtinsert(mp->idtab, &dict[q]);
else if (mp->disc->errorf)
(*mp->disc->errorf)(mp, mp->disc, 3, "out of space");
q = 0;
}
if (mp->idtab)
{
*(b - 1) = 0;
if (ip = (Info_t*)dtmatch(mp->idtab, s))
mp->identifier[ip->value]++;
*(b - 1) = c;
}
s = 0;
if (!mp->idtab)
{
if (mp->idtab = dtnew(mp->vm, &mp->dtdisc, Dtset))
for (q = 0; q < elementsof(dict); q++)
dtinsert(mp->idtab, &dict[q]);
else if (mp->disc->errorf)
(*mp->disc->errorf)(mp, mp->disc, 3, "out of space");
q = 0;
}
if (mp->idtab)
{
*(b - 1) = 0;
if (ip = (Info_t*)dtmatch(mp->idtab, s))
mp->identifier[ip->value]++;
*(b - 1) = c;
}
s = 0;
}
switch (c)
{
case '\t':

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

@ -219,11 +219,11 @@ regsubexec(const regex_t* p, const char* s, size_t nmatch, oldregmatch_t* oldmat
if (!(match = oldof(0, regmatch_t, nmatch, 0)))
return -1;
for (i = 0; i < nmatch; i++)
{
match[i].rm_so = oldmatch[i].rm_so;
match[i].rm_eo = oldmatch[i].rm_eo;
}
for (i = 0; i < nmatch; i++)
{
match[i].rm_so = oldmatch[i].rm_so;
match[i].rm_eo = oldmatch[i].rm_eo;
}
if (!(r = regsubexec_20120528(p, s, nmatch, match)))
for (i = 0; i < nmatch; i++)
{

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)