While mksh R39 builds fine on MirOS #7s8E on my trusty sparc, pgcc 2.95.3

throws out quite some warnings – fix most of them except most emitted via
-Wconversion; work around some others; discard bogus warnings.

sync clog
This commit is contained in:
tg 2009-08-08 13:08:53 +00:00
parent 0d750bba12
commit 0e1266ef90
12 changed files with 87 additions and 71 deletions

View File

@ -1,5 +1,5 @@
#!/bin/sh
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.419 2009/08/01 21:58:06 tg Stab $'
srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.420 2009/08/08 13:08:48 tg Exp $'
#-
# Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009
# Thorsten Glaser <tg@mirbsd.org>
@ -972,7 +972,7 @@ ac_cppflags STDINT_H
#
echo '#include <sys/types.h>
/* check that off_t can represent 2^63-1 correctly, thx FSF */
#define LARGE_OFF_T (((off_t) 1 << 62) - 1 + ((off_t) 1 << 62))
#define LARGE_OFF_T (((off_t)1 << 62) - 1 + ((off_t)1 << 62))
int off_t_is_large[(LARGE_OFF_T % 2147483629 == 721 &&
LARGE_OFF_T % 2147483647 == 1) ? 1 : -1];
int main(void) { return (0); }' >lft.c
@ -1123,7 +1123,7 @@ ac_testn flock_ex '' 'flock and mmap' <<-'EOF'
#include <fcntl.h>
#include <stdlib.h>
int main(void) { return ((void *)mmap(NULL, (size_t)flock(0, LOCK_EX),
PROT_READ, MAP_PRIVATE, 0, 0) == (void *)NULL ? 1 :
PROT_READ, MAP_PRIVATE, 0, (off_t)0) == (void *)NULL ? 1 :
munmap(NULL, 0)); }
EOF
@ -1147,8 +1147,9 @@ ac_test mknod '' 'if to use mknod(), makedev() and friends' <<-'EOF'
#include "sh.h"
int main(int ac, char *av[]) {
dev_t dv;
dv = makedev((unsigned int)ac, 1);
return (mknod(av[0], 0, dv) ? (int)major(dv) : (int)minor(dv));
dv = makedev((unsigned int)ac, (unsigned int)av[0][0]);
return (mknod(av[0], (mode_t)0, dv) ? (int)major(dv) :
(int)minor(dv));
}
EOF
@ -1209,7 +1210,8 @@ ac_test setmode mknod 1 <<-'EOF'
int main(void) { return (thiswillneverbedefinedIhope()); }
#else
#include <unistd.h>
int main(int ac, char *av[]) { return (getmode(setmode(av[0]), ac)); }
int main(int ac, char *av[]) { return (getmode(setmode(av[0]),
(mode_t)ac)); }
#endif
EOF
@ -1242,7 +1244,8 @@ EOF
ac_test strlcpy <<-'EOF'
#include <string.h>
int main(int ac, char *av[]) { return (strlcpy(*av, av[1], ac)); }
int main(int ac, char *av[]) { return (strlcpy(*av, av[1],
(size_t)ac)); }
EOF
#

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.298 2009/08/01 21:57:52 tg Stab $
# $MirOS: src/bin/mksh/check.t,v 1.299 2009/08/08 13:08:48 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -25,7 +25,7 @@
# http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout:
@(#)MIRBSD KSH R39 2009/08/01
@(#)MIRBSD KSH R39 2009/08/08
description:
Check version of shell.
stdin:

8
exec.c
View File

@ -22,7 +22,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.59 2009/06/11 12:42:17 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.60 2009/08/08 13:08:49 tg Exp $");
static int comexec(struct op *, struct tbl *volatile, const char **,
int volatile, volatile int *);
@ -537,7 +537,7 @@ comexec(struct op *t, struct tbl *volatile tp, const char **ap,
break;
case CFUNC: { /* function call */
volatile char old_xflag;
volatile unsigned char old_xflag;
volatile Tflag old_inuse;
const char *volatile old_kshname;
@ -901,7 +901,7 @@ findcom(const char *name, int flags)
static struct tbl temp;
unsigned int h = hash(name);
struct tbl *tp = NULL, *tbi;
int insert = Flag(FTRACKALL); /* insert if not found */
unsigned char insert = Flag(FTRACKALL); /* insert if not found */
char *fpath; /* for function autoloading */
union mksh_cchack npath;
@ -1401,7 +1401,7 @@ static char *plain_fmt_entry(const void *, int, char *, int);
static char *
plain_fmt_entry(const void *arg, int i, char *buf, int buflen)
{
shf_snprintf(buf, buflen, "%s", ((char *const *)arg)[i]);
shf_snprintf(buf, buflen, "%s", ((const char * const *)arg)[i]);
return (buf);
}

6
expr.c
View File

@ -22,7 +22,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.29 2009/06/10 18:12:45 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.30 2009/08/08 13:08:50 tg Exp $");
/* The order of these enums is constrained by the order of opinfo[] */
enum token {
@ -545,8 +545,8 @@ exprtoken(Expr_state *es)
int i, n0;
for (i = 0; (n0 = opinfo[i].name[0]); i++)
if (c == n0 &&
strncmp(cp, opinfo[i].name, opinfo[i].len) == 0) {
if (c == n0 && strncmp(cp, opinfo[i].name,
(size_t)opinfo[i].len) == 0) {
es->tok = (enum token)i;
cp += opinfo[i].len;
break;

22
funcs.c
View File

@ -25,7 +25,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.119 2009/07/30 19:11:11 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.120 2009/08/08 13:08:50 tg Exp $");
#if HAVE_KILLPG
/*
@ -1629,7 +1629,7 @@ c_umask(const char **wp)
}
cp = wp[builtin_opt.optind];
if (cp == NULL) {
old_umask = umask(0);
old_umask = umask((mode_t)0);
umask(old_umask);
if (symbolic) {
char buf[18], *p;
@ -1664,7 +1664,7 @@ c_umask(const char **wp)
int positions, new_val;
char op;
old_umask = umask(0);
old_umask = umask((mode_t)0);
umask(old_umask); /* in case of error */
old_umask = ~old_umask;
new_umask = old_umask;
@ -1978,7 +1978,7 @@ int
c_eval(const char **wp)
{
struct source *s, *saves = source;
char savef;
unsigned char savef;
int rv;
if (ksh_getopt(wp, &builtin_opt, null) == '?')
@ -2402,7 +2402,7 @@ c_mknod(const char **wp)
bi_errorf("invalid file mode");
return (1);
}
mode = getmode(set, DEFFILEMODE);
mode = getmode(set, (mode_t)(DEFFILEMODE));
free(set);
break;
default:
@ -2420,7 +2420,7 @@ c_mknod(const char **wp)
goto c_mknod_usage;
if (set != NULL)
oldmode = umask(0);
oldmode = umask((mode_t)0);
else
mode = DEFFILEMODE;
@ -2623,13 +2623,9 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2,
if ((i = *opnd1 == '!'))
opnd1++;
if ((k = option(opnd1)) == (size_t)-1)
k = 0;
else {
k = Flag(k);
if (i)
k = !k;
}
return (k);
return (0);
s = Flag(k);
return (i ? !s : s);
case TO_FILRD: /* -r */
return (test_eaccess(opnd1, R_OK) == 0);
case TO_FILWR: /* -w */

View File

@ -26,7 +26,7 @@
#include <sys/file.h>
#endif
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.87 2009/08/01 14:07:42 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.88 2009/08/08 13:08:51 tg Exp $");
/*-
* MirOS: This is the default mapping type, and need not be specified.
@ -556,7 +556,7 @@ sethistfile(const char *name)
*/
if (histfd) {
/* yes the file is open */
(void) close(histfd);
(void)close(histfd);
histfd = 0;
hsize = 0;
afree(hname, APERM);
@ -682,9 +682,9 @@ hist_init(Source *s)
if (histfd != fd)
close(fd);
(void) flock(histfd, LOCK_EX);
(void)flock(histfd, LOCK_EX);
hsize = lseek(histfd, 0L, SEEK_END);
hsize = lseek(histfd, (off_t)0, SEEK_END);
if (hsize == 0) {
/* add magic */
@ -697,7 +697,7 @@ hist_init(Source *s)
* we have some data
*/
base = (void *)mmap(NULL, hsize, PROT_READ,
MAP_FILE | MAP_PRIVATE, histfd, 0);
MAP_FILE | MAP_PRIVATE, histfd, (off_t)0);
/*
* check on its validity
*/
@ -731,8 +731,8 @@ hist_init(Source *s)
histload(hist_source, base+2, hsize-2);
munmap((caddr_t)base, hsize);
}
(void) flock(histfd, LOCK_UN);
hsize = lseek(histfd, 0L, SEEK_END);
(void)flock(histfd, LOCK_UN);
hsize = lseek(histfd, (off_t)0, SEEK_END);
#endif
}
@ -931,8 +931,8 @@ writehistfile(int lno, char *cmd)
int bytes;
unsigned char hdr[5];
(void) flock(histfd, LOCK_EX);
sizenow = lseek(histfd, 0L, SEEK_END);
(void)flock(histfd, LOCK_EX);
sizenow = lseek(histfd, (off_t)0, SEEK_END);
if (sizenow != hsize) {
/*
* Things have changed
@ -941,7 +941,7 @@ writehistfile(int lno, char *cmd)
/* someone has added some lines */
bytes = sizenow - hsize;
base = (void *)mmap(NULL, sizenow, PROT_READ,
MAP_FILE | MAP_PRIVATE, histfd, 0);
MAP_FILE | MAP_PRIVATE, histfd, (off_t)0);
if (base == (unsigned char *)MAP_FAILED)
goto bad;
new = base + hsize;
@ -974,8 +974,8 @@ writehistfile(int lno, char *cmd)
if ((write(histfd, hdr, 5) != 5) ||
(write(histfd, cmd, bytes) != bytes))
goto bad;
hsize = lseek(histfd, 0L, SEEK_END);
(void) flock(histfd, LOCK_UN);
hsize = lseek(histfd, (off_t)0, SEEK_END);
(void)flock(histfd, LOCK_UN);
return;
bad:
hist_finish();
@ -984,8 +984,8 @@ writehistfile(int lno, char *cmd)
void
hist_finish(void)
{
(void) flock(histfd, LOCK_UN);
(void) close(histfd);
(void)flock(histfd, LOCK_UN);
(void)close(histfd);
histfd = 0;
}

View File

@ -20,7 +20,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.10 2009/05/16 16:59:37 tg Stab $");
__RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.11 2009/08/08 13:08:51 tg Exp $");
/* build with CPPFLAGS+= -DUSE_REALLOC_MALLOC=0 on ancient systems */
#if defined(USE_REALLOC_MALLOC) && (USE_REALLOC_MALLOC == 0)
@ -29,6 +29,8 @@ __RCSID("$MirOS: src/bin/mksh/lalloc.c,v 1.10 2009/05/16 16:59:37 tg Stab $");
#define remalloc(p,n) realloc((p), (n))
#endif
#define ALLOC_ISUNALIGNED(p) (((ptrdiff_t)(p)) % ALLOC_SIZE)
static ALLOC_ITEM *findptr(ALLOC_ITEM **, char *, Area *);
void
@ -41,12 +43,26 @@ ainit(Area *ap)
static ALLOC_ITEM *
findptr(ALLOC_ITEM **lpp, char *ptr, Area *ap)
{
void *lp;
#ifndef MKSH_SMALL
if (ALLOC_ISUNALIGNED(ptr))
goto fail;
#endif
/* get address of ALLOC_ITEM from user item */
*lpp = (ALLOC_ITEM *)(ptr - ALLOC_SIZE);
/*
* note: the alignment of "ptr" to ALLOC_SIZE is checked
* above; the "void *" gets us rid of a gcc 2.95 warning
*/
*lpp = (lp = ptr - ALLOC_SIZE);
/* search for allocation item in group list */
while (ap->next != *lpp)
if ((ap = ap->next) == NULL)
while (ap->next != lp)
if ((ap = ap->next) == NULL) {
#ifndef MKSH_SMALL
fail:
#endif
internal_errorf("rogue pointer %p", ptr);
}
return (ap);
}
@ -64,7 +80,11 @@ aresize(void *ptr, size_t numb, Area *ap)
}
if ((numb >= SIZE_MAX - ALLOC_SIZE) ||
(lp = remalloc(lp, numb + ALLOC_SIZE)) == NULL)
(lp = remalloc(lp, numb + ALLOC_SIZE)) == NULL
#ifndef MKSH_SMALL
|| ALLOC_ISUNALIGNED(lp)
#endif
)
internal_errorf("cannot allocate %lu data bytes",
(unsigned long)numb);
/* this only works because Area is an ALLOC_ITEM */

11
main.c
View File

@ -33,7 +33,7 @@
#include <locale.h>
#endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.136 2009/07/25 21:31:26 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.137 2009/08/08 13:08:51 tg Exp $");
extern char **environ;
@ -90,7 +90,7 @@ main(int argc, const char *argv[])
int argi, i;
Source *s;
struct block *l;
int restricted, errexit;
unsigned char restricted, errexit;
const char **wp;
pid_t ppid;
struct tbl *vp;
@ -412,8 +412,7 @@ main(int argc, const char *argv[])
/* After typeset command... */
Flag(FRESTRICTED) = 1;
}
if (errexit)
Flag(FERREXIT) = 1;
Flag(FERREXIT) = errexit;
if (Flag(FTALKING)) {
hist_init(s);
@ -1373,8 +1372,8 @@ ktnext(struct tstate *ts)
static int
tnamecmp(const void *p1, const void *p2)
{
const struct tbl *a = *((struct tbl * const *)p1);
const struct tbl *b = *((struct tbl * const *)p2);
const struct tbl *a = *((const struct tbl * const *)p1);
const struct tbl *b = *((const struct tbl * const *)p2);
return (strcmp(a->name, b->name));
}

16
misc.c
View File

@ -29,7 +29,7 @@
#include <grp.h>
#endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.114 2009/08/01 20:31:47 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.115 2009/08/08 13:08:52 tg Exp $");
#undef USE_CHVT
/* XXX conditions correct? */
@ -238,11 +238,9 @@ getoptions(void)
/* change a Flag(*) value; takes care of special actions */
void
change_flag(enum sh_flag f,
int what, /* flag to change */
char newval) /* what is changing the flag (command line vs set) */
change_flag(enum sh_flag f, int what, unsigned int newval)
{
char oldval;
unsigned char oldval;
oldval = Flag(f);
Flag(f) = newval ? 1 : 0; /* needed for tristates */
@ -261,7 +259,7 @@ change_flag(enum sh_flag f,
Flag(FVI) =
#endif
Flag(FEMACS) = Flag(FGMACS) = 0;
Flag(f) = newval;
Flag(f) = (unsigned char)newval;
} else if (f == FPRIVILEGED && oldval && !newval) {
/* Turning off -p? */
#if HAVE_SETRESUGID
@ -284,7 +282,7 @@ change_flag(enum sh_flag f,
/* Changing interactive flag? */
if (f == FTALKING) {
if ((what == OF_CMDLINE || what == OF_SET) && procpid == kshpid)
Flag(FTALKING_I) = newval;
Flag(FTALKING_I) = (unsigned char)newval;
}
}
@ -791,7 +789,7 @@ pat_scan(const unsigned char *p, const unsigned char *pe, int match_sep)
int
xstrcmp(const void *p1, const void *p2)
{
return (strcmp(*(char * const *)p1, *(char * const *)p2));
return (strcmp(*(const char * const *)p1, *(const char * const *)p2));
}
/* Initialise a Getopt structure */
@ -1377,7 +1375,7 @@ chvt(const char *fn)
errorf("chvt: not a char device: %s", fn);
if ((sb.st_uid != 0) && chown(fn, 0, 0))
warningf(false, "chvt: cannot chown root %s", fn);
if (((sb.st_mode & 07777) != 0600) && chmod(fn, 0600))
if (((sb.st_mode & 07777) != 0600) && chmod(fn, (mode_t)0600))
warningf(false, "chvt: cannot chmod 0600 %s", fn);
#if HAVE_REVOKE
if (revoke(fn))

8
sh.h
View File

@ -134,9 +134,9 @@
#endif
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.321 2009/08/01 20:32:45 tg Rel $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.322 2009/08/08 13:08:52 tg Exp $");
#endif
#define MKSH_VERSION "R39 2009/08/01"
#define MKSH_VERSION "R39 2009/08/08"
#ifndef MKSH_INCLUDES_ONLY
@ -594,7 +594,7 @@ enum sh_flag {
#define Flag(f) (shell_flags[(int)(f)])
#define UTFMODE Flag(FUTFMODE)
EXTERN char shell_flags[FNFLAGS];
EXTERN unsigned char shell_flags[FNFLAGS];
/* null value for variable; comparision pointer for unset */
EXTERN char null[] I__("");
@ -1551,7 +1551,7 @@ void setctypes(const char *, int);
void initctypes(void);
size_t option(const char *);
char *getoptions(void);
void change_flag(enum sh_flag, int, char);
void change_flag(enum sh_flag, int, unsigned int);
int parse_args(const char **, int, int *);
int getn(const char *, int *);
int bi_getn(const char *, int *);

4
shf.c
View File

@ -22,7 +22,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.30 2009/06/10 18:12:49 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.31 2009/08/08 13:08:53 tg Exp $");
/* flags to shf_emptybuf() */
#define EB_READSW 0x01 /* about to switch to reading */
@ -299,7 +299,7 @@ shf_flush(struct shf *shf)
if (shf->flags & SHF_READING) {
shf->flags &= ~(SHF_EOF | SHF_READING);
if (shf->rnleft > 0) {
lseek(shf->fd, (off_t) -shf->rnleft, SEEK_CUR);
lseek(shf->fd, (off_t)-shf->rnleft, SEEK_CUR);
shf->rnleft = 0;
shf->rp = shf->buf;
}

4
var.c
View File

@ -22,7 +22,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.76 2009/08/01 20:32:45 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.77 2009/08/08 13:08:53 tg Exp $");
/*
* Variables
@ -919,7 +919,7 @@ makenv(void)
*/
#if HAVE_ARC4RANDOM && !defined(MKSH_SMALL)
static uint32_t rnd_cache[2];
static char rnd_lastflag = 2;
static unsigned char rnd_lastflag = 2;
#endif
static int