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

@ -819,6 +819,7 @@ void ed_setup(register Edit_t *ep, int fd, int reedit)
sh_offoption(SH_RESTRICTED);
sh_offoption(SH_VERBOSE);
sh_offoption(SH_XTRACE);
/* get the cursor up sequence from tput */
#if _tput_terminfo
sh_trap(".sh.subscript=$(" _pth_tput " cuu1 2>/dev/null)",0);
#elif _tput_termcap
@ -914,6 +915,7 @@ int ed_read(void *context, int fd, char *buff, int size, int reedit)
if(0)
#endif
{
/* redraw the prompt after receiving SIGWINCH */
Edpos_t lastpos;
int n, rows, newsize;
/* move cursor to start of first line */
@ -1809,10 +1811,8 @@ int ed_histgen(Edit_t *ep,const char *pattern)
{
l = ac;
argv = av = (char**)stakalloc((ac+1)*sizeof(char*));
for(mplast=0; l>=0 && (*av= (char*)mp); mplast=mp,mp=mp->next,av++)
{
for(; l>=0 && (*av= (char*)mp); mp=mp->next,av++)
l--;
}
*av = 0;
strsort(argv,ac,ed_sortdata);
mplast = (Histmatch_t*)argv[0];

View file

@ -213,8 +213,9 @@ int ed_emacsread(void *context, int fd,char *buff,int scend, int reedit)
/* This mess in case the read system call fails */
ed_setup(ep->ed,fd,reedit);
#if !SHOPT_MULTIBYTE
out = (genchar*)buff;
#if SHOPT_MULTIBYTE
#else
out = (genchar*)roundof(buff-(char*)0,sizeof(genchar));
if(reedit)
ed_internal(buff,out);
@ -829,10 +830,10 @@ static int escape(register Emacs_t* ep,register genchar *out,int count)
#endif
return(-1);
case 'l': /* M-l == lower-case */
case 'd':
case 'c':
case 'f':
case 'l': /* M-l == lowercase */
case 'd': /* M-d == delete word */
case 'c': /* M-c == uppercase */
case 'f': /* M-f == move cursor forward one word */
{
i = cur;
while(value-- && i<eol)
@ -886,10 +887,10 @@ static int escape(register Emacs_t* ep,register genchar *out,int count)
}
case 'b':
case 'b': /* M-b == go backward one word */
case DELETE :
case '\b':
case 'h':
case 'h': /* M-h == delete the previous word */
{
i = cur;
while(value-- && i>0)
@ -1097,6 +1098,7 @@ static int escape(register Emacs_t* ep,register genchar *out,int count)
if(cur>0 && eol==cur && (cur<(SEARCHSIZE-2) || ep->prevdirection == -2))
#endif /* SHOPT_EDPREDICT */
{
/* perform a reverse search based on the current command line */
if(ep->lastdraw==APPEND)
{
out[cur] = 0;
@ -1305,7 +1307,7 @@ static void search(Emacs_t* ep,genchar *out,int direction)
goto restore;
continue;
}
if(i == ep->ed->e_intr)
if(i == ep->ed->e_intr) /* end reverse search */
goto restore;
if (i==usrkill)
{

View file

@ -116,7 +116,6 @@ static int hist_exceptf(Sfio_t*, int, void*, Sfdisc_t*);
static int histinit;
static mode_t histmode;
static History_t *wasopen;
static History_t *hist_ptr;
#if SHOPT_ACCTFILE

View file

@ -1452,6 +1452,7 @@ static void getline(register Vi_t* vp,register int mode)
case '\b': /** backspace **/
if( sh_isoption(SH_VI) && backslash && virtual[cur_virt] == '\\' )
{
/*** escape backspace/erase char ***/
backslash = 0;
cdelete(vp,1, BAD);
append(vp,usrerase, mode);
@ -1498,6 +1499,7 @@ static void getline(register Vi_t* vp,register int mode)
case UKILL: /** user kill line char **/
if( sh_isoption(SH_VI) && backslash && virtual[cur_virt] == '\\' )
{
/*** escape kill char ***/
backslash = 0;
cdelete(vp,1, BAD);
append(vp,usrkill, mode);