1
0
Fork 0
mirror of git://git.code.sf.net/p/cdesktopenv/code synced 2025-03-09 15:50:02 +00:00

Fix various compiler warnings and minor issues (#362)

List of changes:
- Fixed some -Wuninitialized warnings and removed some unused variables.

- Removed the unused extern for B_login (re: d8eba9d1).

- The libcmd builtins and the vmalloc memfatal function now handle
  memory errors with 'ERROR_SYSTEM|ERROR_PANIC' for consistency with how
  ksh itself handles out of memory errors.

- Added usage of UNREACHABLE() where it was missing from error handling.

- Extend many variables from short to int to prevent overflows (most
  variables involve file descriptors).

- Backported a ksh2020 patch to fix unused value Coverity issues
  (https://github.com/att/ast/pull/740).

- Note in src/cmd/ksh93/README that ksh compiles with Cygwin on
  Windows 10 and Windows 11, albeit with many test failures.

- Add comments to detail some sections of code. Extensive list of
  commits related to this change:
  ca2443b5, 7e7f1372, 2db9953a, 7003aba4, 6f50ff64, b1a41311,
  222515bf, a0dcdeea, 0aa9e03f, 61437b27, 352e68da, 88e8fa67,
  bc8b36fa, 6e515f1d, 017d088c, 035a4cb3, 588a1ff7, 6d63b57d,
  a2f13c19, 794d1c86, ab98ec65, 1026006d

- Removed a lot of dead ifdef code.

- edit/emacs.c: Hide an assignment to avoid a -Wunused warning. (See
  also https://github.com/att/ast/pull/753, which removed the assignment
  because ksh2020 removed the !SHOPT_MULTIBYTE code.)

- sh/nvdisc.c: The sh_newof macro cannot return a null pointer because
  it will instead cause the shell to exit if memory cannot be allocated.
  That makes the if statement here a no-op, so remove it.

- sh/xec.c: Fixed one unused variable warning in sh_funscope().

- sh/xec.c: Remove a fallthrough comment added in commit ed478ab7
  because the TFORK code doesn't fall through (GCC also produces no
  -Wimplicit-fallthrough warning here).

- data/builtins.c: The cd and pwd man pages state that these builtins
  default to -P if PATH_RESOLVE is 'physical', which isn't accurate:
     $ /opt/ast/bin/getconf PATH_RESOLVE
     physical
     $ mkdir /tmp/dir; ln -s /tmp/dir /tmp/sym
     $ cd /tmp/sym
     $ pwd
     /tmp/sym
     $ cd -P /tmp/sym
     $ pwd
     /tmp/dir
  The behavior described by these man pages isn't specified in the ksh
  man page or by POSIX, so to avoid changing these builtin's behavior
  the inaccurate PATH_RESOLVE information has been removed.

- Mamfiles: Preserve multi-line errors by quoting the $x variable.
  This fix was backported from 93v-.
  (See also <a7e9cc82>.)

- sh/subshell.c: Remove set but not used sp->errcontext variable.
This commit is contained in:
Johnothan King 2021-12-07 22:51:38 -08:00 committed by Martijn Dekker
parent b3050769ea
commit beccb93fd4
66 changed files with 148 additions and 265 deletions

View file

@ -324,8 +324,8 @@ make install
exec - esac
exec - continue
exec - elif test ! -f ${INSTALLROOT}/lib/lib$i.a
exec - then case `{ ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' $x ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - *$x*) case `{ ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' $x ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - then case `{ ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' "$x" ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - *$x*) case `{ ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' "$x" ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - *$x*) continue ;;
exec - esac
exec - ;;

View file

@ -382,9 +382,6 @@ error(DEBUG_TRACE, "AHA#%d _win_iconv from=0x%04x to=0x%04x\n", __LINE__, cc->fr
goto nope;
#if DEBUG_TRACE
error(DEBUG_TRACE, "AHA#%d _win_iconv *fn=%u fz=%u[%u] *tn=%u tz=%u\n", __LINE__, *fn, fz, fz * sizeof(WCHAR), *tn, tz);
#endif
#if 0
fz *= sizeof(WCHAR);
#endif
}
if (ub != (LPWSTR)*fb)

View file

@ -548,20 +548,12 @@ sjis_mbtowc(register wchar_t* p, register const char* s, size_t n)
#endif
#if 0
#define utf8_wctomb wctomb
#else
static int
utf8_wctomb(char* u, wchar_t w)
{
return u ? wc2utf8(u, w) : 0;
}
#endif
static const uint32_t utf8mask[] =
{
0x00000000,

View file

@ -172,10 +172,6 @@ spawnveg(const char* path, char* const argv[], char* const envv[], pid_t pgid)
#endif
#endif
#if 0
if (access(path, X_OK))
return -1;
#endif
if (!envv)
envv = environ;
#if _lib_spawnve

View file

@ -55,12 +55,12 @@ nomalloc(Vmalloc_t* region, int type, void* obj, Vmdisc_t* disc)
{
#ifdef VM_BADADDR
case VM_BADADDR:
error(ERROR_SYSTEM|3, "invalid pointer %p passed to free or realloc", obj);
error(ERROR_SYSTEM|ERROR_PANIC, "invalid pointer %p passed to free or realloc", obj);
UNREACHABLE();
#endif
case VM_NOMEM:
vmstat(region, &st);
error(ERROR_SYSTEM|3, "storage allocator out of memory on %lu byte request ( region %lu segments %lu busy %lu:%lu:%lu free %lu:%lu:%lu )", (size_t)obj, st.extent, st.n_seg, st.n_busy, st.s_busy, st.m_busy, st.n_free, st.s_free, st.m_free);
error(ERROR_SYSTEM|ERROR_PANIC, "storage allocator out of memory on %lu byte request ( region %lu segments %lu busy %lu:%lu:%lu free %lu:%lu:%lu )", (size_t)obj, st.extent, st.n_seg, st.n_busy, st.s_busy, st.m_busy, st.n_free, st.s_free, st.m_free);
UNREACHABLE();
}
return(0);

View file

@ -828,6 +828,7 @@ fts_read(register FTS* fts)
struct stat sb;
#endif
f = 0;
for (;;)
switch (fts->state)
{

View file

@ -90,7 +90,6 @@ pathpath_20100601(const char* p, const char* a, int mode, register char* path, s
a = 0;
else if (s = (char*)a)
{
x = s;
if (strchr(p, '/'))
{
a = p;

View file

@ -67,13 +67,6 @@ wideread(Sfio_t* f, Void_t* buf, size_t size, Sfdisc_t* dp)
{
register Wide_t* w = (Wide_t*)dp;
wchar_t wuf[2];
#if 0
if (sfread(w->f, wuf, sizeof(wuf[0])) != sizeof(wuf[0]))
return -1;
wuf[1] = 0;
return wcstombs(buf, wuf, size);
#else
ssize_t r;
r = sfread(w->f, wuf, sizeof(wuf[0]));
@ -82,7 +75,6 @@ wideread(Sfio_t* f, Void_t* buf, size_t size, Sfdisc_t* dp)
wuf[1] = 0;
r = wcstombs(buf, wuf, size);
return r;
#endif
}
int

View file

@ -356,10 +356,6 @@ tmxfmt(char* buf, size_t len, const char* format, Time_t t)
case 'N': /* (AST|GNU) nanosecond part */
cp = number(cp, ep, (long)tm->tm_nsec, 9, width, pad);
continue;
#if 0
case 'o': /* (UNUSED) */
continue;
#endif
case 'p': /* meridian */
n = TM_MERIDIAN + (tm->tm_hour >= 12);
goto index;
@ -574,10 +570,6 @@ tmxfmt(char* buf, size_t len, const char* format, Time_t t)
case 'U': /* week number, Sunday as first day */
cp = number(cp, ep, (long)tmweek(tm, 0, -1, -1), 2, width, pad);
continue;
#if 0
case 'v': /* (UNUSED) */
continue;
#endif
case 'V': /* ISO week number */
cp = number(cp, ep, (long)tmweek(tm, 2, -1, -1), 2, width, pad);
continue;

View file

@ -44,8 +44,8 @@ make install
exec - esac
exec - continue
exec - elif test ! -f ${INSTALLROOT}/lib/lib$i.a
exec - then case `{ ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} -L${INSTALLROOT}/lib ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' $x ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - *$x*) case `{ ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' $x ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - then case `{ ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} -L${INSTALLROOT}/lib ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' "$x" ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - *$x*) case `{ ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' "$x" ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - *$x*) continue ;;
exec - esac
exec - ;;

View file

@ -299,7 +299,7 @@ b_chgrp(int argc, char** argv, Shbltin_t* context)
mapdisc.size = sizeof(Key_t);
if (!(map = dtopen(&mapdisc, Dtset)))
{
error(ERROR_exit(1), "out of memory [id map]");
error(ERROR_SYSTEM|ERROR_PANIC, "out of memory [id map]");
UNREACHABLE();
}
continue;
@ -383,7 +383,7 @@ b_chgrp(int argc, char** argv, Shbltin_t* context)
{
if (!(m = (Map_t*)stakalloc(sizeof(Map_t))))
{
error(ERROR_exit(1), "out of memory [id dictionary]");
error(ERROR_SYSTEM|ERROR_PANIC, "out of memory [id dictionary]");
UNREACHABLE();
}
m->key = key;

View file

@ -232,16 +232,6 @@ cmp(const char* file1, Sfio_t* f1, const char* file2, Sfio_t* f2, int flags, Sfo
return 1;
differences--;
}
#if 0
if (!flags)
sfprintf(sfstdout, "%s %s differ: char %I*d, line %I*u\n", file1, file2, sizeof(pos), pos - (last - p1), sizeof(lines), lines);
else
{
sfprintf(sfstdout, "%6I*d", sizeof(pos), pos - (last - p1));
pretty(sfstdout, c1, -1, flags);
pretty(sfstdout, *(p2-1), '\n', flags);
}
#else
if (flags & CMP_VERBOSE)
sfprintf(sfstdout, "%6I*d", sizeof(pos), pos - (last - p1));
else
@ -254,7 +244,6 @@ cmp(const char* file1, Sfio_t* f1, const char* file2, Sfio_t* f2, int flags, Sfo
}
else
sfputc(sfstdout, '\n');
#endif
if (!differences || differences < 0 && !(flags & CMP_VERBOSE))
return 1;
ret = 1;

View file

@ -291,7 +291,7 @@ visit(State_t* state, register FTSENT* ent)
{
if ((state->postsiz + len) > state->pathsiz && !(state->path = newof(state->path, char, state->pathsiz = roundof(state->postsiz + len, PATH_CHUNK), 0)))
{
error(ERROR_SYSTEM|3, "out of memory");
error(ERROR_SYSTEM|ERROR_PANIC, "out of memory");
UNREACHABLE();
}
if (state->hierarchy && ent->fts_level == 0 && strchr(base, '/'))
@ -400,15 +400,6 @@ visit(State_t* state, register FTSENT* ent)
return 0;
}
break;
#if 0
case FTS_SL:
if (state->op == CP)
{
error(2, "%s: cannot copy non-terminal symbolic link", ent->fts_path);
return 0;
}
break;
#endif
}
if (state->directory)
memcpy(state->path + state->postsiz, base, len);
@ -696,7 +687,7 @@ b_cp(int argc, register char** argv, Shbltin_t* context)
{
if (!(state = newof(0, State_t, 1, 0)))
{
error(ERROR_SYSTEM|3, "out of memory");
error(ERROR_SYSTEM|ERROR_PANIC, "out of memory");
UNREACHABLE();
}
if (sh)
@ -874,7 +865,7 @@ b_cp(int argc, register char** argv, Shbltin_t* context)
continue;
case '?':
error(ERROR_USAGE|4, "%s", opt_info.arg);
continue;
UNREACHABLE();
case ':':
error(2, "%s", opt_info.arg);
continue;
@ -890,7 +881,7 @@ b_cp(int argc, register char** argv, Shbltin_t* context)
}
if (!(v = (char**)stkalloc(stkstd, (argc + 2) * sizeof(char*))))
{
error(ERROR_SYSTEM|3, "out of memory");
error(ERROR_SYSTEM|ERROR_PANIC, "out of memory");
UNREACHABLE();
}
memcpy(v, argv, (argc + 1) * sizeof(char*));
@ -986,7 +977,7 @@ b_cp(int argc, register char** argv, Shbltin_t* context)
state->postsiz = strlen(file);
if (state->pathsiz < roundof(state->postsiz + 2, PATH_CHUNK) && !(state->path = newof(state->path, char, state->pathsiz = roundof(state->postsiz + 2, PATH_CHUNK), 0)))
{
error(ERROR_SYSTEM|3, "out of memory");
error(ERROR_SYSTEM|ERROR_PANIC, "out of memory");
UNREACHABLE();
}
memcpy(state->path, file, state->postsiz + 1);

View file

@ -140,7 +140,7 @@ cutinit(int mode, char* str, Delim_t* wdelim, Delim_t* ldelim, size_t reclen)
if (!(cut = (Cut_t*)stakalloc(sizeof(Cut_t) + strlen(cp) * sizeof(int))))
{
error(ERROR_exit(1), "out of memory");
error(ERROR_SYSTEM|ERROR_PANIC, "out of memory");
UNREACHABLE();
}
if (cut->mb = mbwide())

View file

@ -343,7 +343,7 @@ b_date(int argc, register char** argv, Shbltin_t* context)
case 'p':
if (!(f = newof(0, Fmt_t, 1, 0)))
{
error(ERROR_SYSTEM|3, "out of memory [format]");
error(ERROR_SYSTEM|ERROR_PANIC, "out of memory [format]");
UNREACHABLE();
}
f->next = fmts;

View file

@ -537,38 +537,31 @@ b_expr(int argc, char** argv, Shbltin_t* context)
cmdinit(argc, argv, context, ERROR_CATALOG, 0);
state.standard = !!conformance(0, 0);
#if 0
if (state.standard)
state.arglist = argv+1;
else
#endif
while (n=optget(argv, usage))
{
while (n=optget(argv, usage))
/*
* NOTE: this loop ignores all but literal -- and -?
* out of kindness for obsolescent usage
* (and is ok with the standard) but strict
* getopt conformance would give usage for all
* unknown - options
*/
if(n=='?')
{
/*
* NOTE: this loop ignores all but literal -- and -?
* out of kindness for obsolescent usage
* (and is ok with the standard) but strict
* getopt conformance would give usage for all
* unknown - options
*/
if(n=='?')
{
error(ERROR_usage(2), "%s", opt_info.arg);
UNREACHABLE();
}
if (opt_info.option[1] != '?')
break;
error(ERROR_usage(2), "%s", opt_info.arg);
UNREACHABLE();
}
if (error_info.errors)
{
error(ERROR_usage(2),"%s",optusage((char*)0));
UNREACHABLE();
}
state.arglist = argv+opt_info.index;
if (opt_info.option[1] != '?')
break;
error(ERROR_usage(2), "%s", opt_info.arg);
UNREACHABLE();
}
if (error_info.errors)
{
error(ERROR_usage(2),"%s",optusage((char*)0));
UNREACHABLE();
}
state.arglist = argv+opt_info.index;
if (expr_or(&state, &node))
{
error(ERROR_exit(2),"syntax error");

View file

@ -234,7 +234,7 @@ getids(Sfio_t* sp, const char* name, register int flags)
maxgroups = NGROUPS_MAX;
if (!(groups = newof(0, gid_t, maxgroups + 1, 0)))
{
error(ERROR_exit(1), "out of memory [group array]");
error(ERROR_SYSTEM|ERROR_PANIC, "out of memory [group array]");
UNREACHABLE();
}
}

View file

@ -705,8 +705,9 @@ sfprintf(sfstdout, "[2#%d:0,%lld,%lld]", __LINE__, lo, hi);
jp->samesize = roundof(n2, 16);
if (!(jp->same = newof(jp->same, char, jp->samesize, 0)))
{
error(ERROR_SYSTEM|2, "out of memory");
return -1;
done(jp);
error(ERROR_SYSTEM|ERROR_PANIC, "out of memory");
UNREACHABLE();
}
}
memcpy(jp->same, cp2, o2 = n2);
@ -826,7 +827,7 @@ b_join(int argc, char** argv, Shbltin_t* context)
#endif
if (!(jp = init()))
{
error(ERROR_system(1),"out of memory");
error(ERROR_SYSTEM|ERROR_PANIC,"out of memory");
UNREACHABLE();
}
jp->context = context;

View file

@ -218,7 +218,7 @@ b_paste(int argc, char** argv, Shbltin_t* context)
}
if (!(delim = strdup(delim)))
{
error(ERROR_system(1), "out of memory");
error(ERROR_SYSTEM|ERROR_PANIC, "out of memory");
UNREACHABLE();
}
dlen = dsiz = stresc(delim);
@ -238,7 +238,7 @@ b_paste(int argc, char** argv, Shbltin_t* context)
if (!(mp = newof(0, Delim_t, dlen, 0)))
{
free(delim);
error(ERROR_system(1), "out of memory");
error(ERROR_SYSTEM|ERROR_PANIC, "out of memory");
UNREACHABLE();
}
cp = delim;
@ -263,7 +263,7 @@ b_paste(int argc, char** argv, Shbltin_t* context)
{
if (!(streams = (Sfio_t**)stakalloc(n*sizeof(Sfio_t*))))
{
error(ERROR_exit(1), "out of memory");
error(ERROR_SYSTEM|ERROR_PANIC, "out of memory");
UNREACHABLE();
}
n = 0;

View file

@ -77,8 +77,8 @@ static int rev_char(Sfio_t *in, Sfio_t *out)
w = roundof(n + 1, 1024);
if (!(wp = newof(wp, wchar_t, w, 0)))
{
error(ERROR_SYSTEM|2, "out of memory");
return 0;
error(ERROR_SYSTEM|ERROR_PANIC, "out of memory");
UNREACHABLE();
}
}
xp = wp;

View file

@ -614,12 +614,15 @@ b_tail(int argc, char** argv, Shbltin_t* context)
error(ERROR_warn(0), "--log ignored for --notimeout");
}
if (error_info.errors)
{
error(ERROR_usage(2), "%s", optusage(NiL));
UNREACHABLE();
}
if (flags & FOLLOW)
{
if (!(fp = (Tail_t*)stakalloc(argc * sizeof(Tail_t))))
{
error(ERROR_system(1), "out of memory");
error(ERROR_SYSTEM|ERROR_PANIC, "out of memory");
UNREACHABLE();
}
files = 0;

View file

@ -197,7 +197,10 @@ b_tee(int argc, register char** argv, Shbltin_t* context)
}
}
else
error(ERROR_exit(0), "out of memory");
{
error(ERROR_SYSTEM|ERROR_PANIC, "out of memory");
UNREACHABLE();
}
}
if ((sfmove(sfstdin, sfstdout, SF_UNBOUND, -1) < 0 || !sfeof(sfstdin)) && !ERROR_PIPE(errno) && errno != EINTR)
error(ERROR_system(0), "read error");

View file

@ -464,10 +464,7 @@ int wc_count(Wc_t *wp, Sfio_t *fd, const char* file)
while(mbc(c) && ((c|WC_ERR) || (c&7)==0))
c=type[*cp++];
if(eol(c) && (cp > endbuff))
{
c = WC_MB|WC_ERR;
goto eob;
}
if(mbc(c))
goto mbyte;
else if(c&WC_SP)

View file

@ -44,8 +44,8 @@ make install
exec - esac
exec - continue
exec - elif test ! -f ${INSTALLROOT}/lib/lib$i.a
exec - then case `{ ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} -L${INSTALLROOT}/lib ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' $x ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - *$x*) case `{ ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' $x ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - then case `{ ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} -L${INSTALLROOT}/lib ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' "$x" ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - *$x*) case `{ ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' "$x" ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - *$x*) continue ;;
exec - esac
exec - ;;

View file

@ -44,8 +44,8 @@ make install
exec - esac
exec - continue
exec - elif test ! -f ${INSTALLROOT}/lib/lib$i.a
exec - then case `{ ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} -L${INSTALLROOT}/lib ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' $x ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - *$x*) case `{ ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' $x ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - then case `{ ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} -L${INSTALLROOT}/lib ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' "$x" ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - *$x*) case `{ ${CC} ${mam_cc_FLAGS} ${KSH_RELFLAGS} ${CCFLAGS} ${LDFLAGS} -o 1.${COTEMP}.x 1.${COTEMP}.o -l$i 2>&1 || echo '' "$x" ;} | sed -e 's/[][()+@?]/#/g' || :` in
exec - *$x*) continue ;;
exec - esac
exec - ;;