From b90007d7843bd8b96d62ff4eff3259f724987041 Mon Sep 17 00:00:00 2001 From: tg Date: Wed, 27 May 2009 09:58:24 +0000 Subject: [PATCH] =?UTF-8?q?=E2=80=A2=20Build.sh,=20strlcpy.c:=20gcc-curren?= =?UTF-8?q?t=20conversion=20&c.=20warnings=20cleanup=20=E2=80=A2=20histrap?= =?UTF-8?q?.c,=20lex.c,=20misc.c:=20get=20average=20stack=20frame=20size?= =?UTF-8?q?=20to=20<=3D=20768=20bytes=20=E2=80=A2=20check.t,=20sh.h:=20bum?= =?UTF-8?q?p=20version?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Build.sh | 30 ++++++++++++++++-------------- check.t | 4 ++-- histrap.c | 33 +++++++++++++++++++-------------- lex.c | 6 +----- misc.c | 25 ++++++++++++++----------- sh.h | 4 ++-- strlcpy.c | 6 +++--- 7 files changed, 57 insertions(+), 51 deletions(-) diff --git a/Build.sh b/Build.sh index 22e69f7..75e54ac 100644 --- a/Build.sh +++ b/Build.sh @@ -1,5 +1,5 @@ #!/bin/sh -srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.394 2009/05/20 10:10:35 tg Exp $' +srcversion='$MirOS: src/bin/mksh/Build.sh,v 1.395 2009/05/27 09:58:20 tg Stab $' #- # Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009 # Thorsten Glaser @@ -867,7 +867,7 @@ ac_test attribute_bounded attribute 0 'for __attribute__((bounded))' <<-'EOF' __attribute__((bounded (buffer, 2, 3))); int main(int ac, char *av[]) { return (xcopy(av[0], av[--ac], 1)); } int xcopy(const void *s, void *d, size_t n) { - memmove(d, s, n); return (n); + memmove(d, s, n); return ((int)n); } EOF @@ -1060,7 +1060,7 @@ ac_testn arc4random <<-'EOF' #include #endif extern u_int32_t arc4random(void); - int main(void) { return (arc4random()); } + int main(void) { return ((int)(arc4random() & 0xFF)); } EOF save_LIBS=$LIBS @@ -1084,7 +1084,8 @@ ac_test arc4random_pushb arc4random 0 <<-'EOF' #include #endif extern uint32_t arc4random_pushb(void *, size_t); - int main(int ac, char *av[]) { return (arc4random_pushb(*av, ac)); } + int main(int ac, char *av[]) { return ((int)(arc4random_pushb(*av, + (size_t)ac)) & 0xFF); } EOF LIBS=$save_LIBS @@ -1094,7 +1095,7 @@ ac_testn flock_ex '' 'flock and mmap' <<-'EOF' #include #include #include - int main(void) { return ((void *)mmap(NULL, flock(0, LOCK_EX), + int main(void) { return ((void *)mmap(NULL, (size_t)flock(0, LOCK_EX), PROT_READ, MAP_PRIVATE, 0, 0) == (void *)NULL ? 1 : munmap(NULL, 0)); } EOF @@ -1104,7 +1105,8 @@ ac_test getrusage <<-'EOF' #include "sh.h" int main(void) { struct rusage ru; - return (getrusage(RUSAGE_SELF + RUSAGE_CHILDREN, &ru)); + return (getrusage(RUSAGE_SELF, &ru) + + getrusage(RUSAGE_CHILDREN, &ru)); } EOF @@ -1113,7 +1115,7 @@ 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(ac, 1); + dv = makedev((unsigned int)ac, 1); return (mknod(av[0], 0, dv) ? (int)major(dv) : (int)minor(dv)); } EOF @@ -1156,13 +1158,13 @@ EOF ac_test setlocale_ctype '' 'setlocale(LC_CTYPE, "")' <<-'EOF' #include #include - int main(void) { return ((ptrdiff_t)(void *)setlocale(LC_CTYPE, "")); } + int main(void) { return ((int)(ptrdiff_t)(void *)setlocale(LC_CTYPE, "")); } EOF ac_test langinfo_codeset setlocale_ctype 0 'nl_langinfo(CODESET)' <<-'EOF' #include #include - int main(void) { return ((ptrdiff_t)(void *)nl_langinfo(CODESET)); } + int main(void) { return ((int)(ptrdiff_t)(void *)nl_langinfo(CODESET)); } EOF ac_test setmode mknod 1 <<-'EOF' @@ -1198,7 +1200,7 @@ ac_test strcasestr <<-'EOF' #include #endif int main(int ac, char *av[]) { - return ((ptrdiff_t)(void *)strcasestr(*av, av[ac])); + return ((int)(ptrdiff_t)(void *)strcasestr(*av, av[ac])); } EOF @@ -1216,25 +1218,25 @@ ac_test '!' arc4random_decl arc4random 1 'if arc4random() does not need to be de #define MKSH_INCLUDES_ONLY #include "sh.h" long arc4random(void); /* this clashes if defined before */ - int main(void) { return (arc4random()); } + int main(void) { return ((int)arc4random()); } EOF ac_test '!' arc4random_pushb_decl arc4random_pushb 1 'if arc4random_pushb() does not need to be declared' <<-'EOF' #define MKSH_INCLUDES_ONLY #include "sh.h" int arc4random_pushb(char, int); /* this clashes if defined before */ - int main(int ac, char *av[]) { return (arc4random_pushb(**av, ac)); } + int main(int ac, char *av[]) { return ((int)arc4random_pushb(**av, ac)); } EOF ac_test '!' flock_decl flock_ex 1 'if flock() does not need to be declared' <<-'EOF' #define MKSH_INCLUDES_ONLY #include "sh.h" long flock(void); /* this clashes if defined before */ - int main(void) { return (flock()); } + int main(void) { return ((int)flock()); } EOF ac_test '!' revoke_decl revoke 1 'if revoke() does not need to be declared' <<-'EOF' #define MKSH_INCLUDES_ONLY #include "sh.h" long revoke(void); /* this clashes if defined before */ - int main(void) { return (revoke()); } + int main(void) { return ((int)revoke()); } EOF ac_test sys_siglist_decl sys_siglist 1 'if sys_siglist[] does not need to be declared' <<-'EOF' #define MKSH_INCLUDES_ONLY diff --git a/check.t b/check.t index 23193f8..dcafafb 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.279 2009/05/21 14:28:32 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.280 2009/05/27 09:58:21 tg Stab $ # $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 R38 2009/05/21 + @(#)MIRBSD KSH R38 2009/05/27 description: Check version of shell. stdin: diff --git a/histrap.c b/histrap.c index 1425b0f..d0000f5 100644 --- a/histrap.c +++ b/histrap.c @@ -26,7 +26,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.81 2009/05/16 18:40:06 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/histrap.c,v 1.82 2009/05/27 09:58:22 tg Exp $"); /*- * MirOS: This is the default mapping type, and need not be specified. @@ -781,8 +781,8 @@ hist_count_lines(unsigned char *base, int bytes) static int hist_shrink(unsigned char *oldbase, int oldbytes) { - int fd; - char nfile[PATH_MAX]; + int fd, rv = 0; + char *nfile = NULL; struct stat statb; unsigned char *nbase = oldbase; int nbytes = oldbytes; @@ -796,27 +796,32 @@ hist_shrink(unsigned char *oldbase, int oldbytes) /* * create temp file */ - shf_snprintf(nfile, sizeof(nfile), "%s.%d", hname, (int)procpid); + nfile = shf_smprintf("%s.%d", hname, (int)procpid); if ((fd = open(nfile, O_CREAT | O_TRUNC | O_WRONLY, 0600)) < 0) - return 1; + goto errout; if (fstat(histfd, &statb) >= 0 && chown(nfile, statb.st_uid, statb.st_gid)) goto errout; - if (sprinkle(fd) || write(fd, nbase, nbytes) != nbytes) { - errout: - close(fd); - unlink(nfile); - return 1; - } + if (sprinkle(fd) || write(fd, nbase, nbytes) != nbytes) + goto errout; close(fd); + fd = -1; /* * rename */ - if (rename(nfile, hname) < 0) - return 1; - return 0; + if (rename(nfile, hname) < 0) { + errout: + if (fd >= 0) { + close(fd); + if (nfile) + unlink(nfile); + } + rv = 1; + } + afree(nfile, ATEMP); + return (rv); } /* diff --git a/lex.c b/lex.c index ff4774a..74d26a3 100644 --- a/lex.c +++ b/lex.c @@ -22,7 +22,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.83 2009/05/16 16:59:37 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/lex.c,v 1.84 2009/05/27 09:58:22 tg Exp $"); /* * states while lexing word @@ -127,11 +127,7 @@ static int ignore_backslash_newline; #define getsc_() ((*source->str != '\0') && !(source->flags & SF_FIRST) \ ? *source->str++ : getsc__()) -#ifdef MKSH_SMALL #define STATE_BSIZE 32 -#else -#define STATE_BSIZE 48 -#endif #define PUSH_STATE(s) do { \ if (++statep == state_info.end) \ diff --git a/misc.c b/misc.c index 35ba8e4..4f928ec 100644 --- a/misc.c +++ b/misc.c @@ -29,7 +29,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.106 2009/05/16 18:40:07 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.107 2009/05/27 09:58:23 tg Exp $"); #undef USE_CHVT #if defined(TIOCSCTTY) && !defined(MKSH_SMALL) @@ -1300,10 +1300,10 @@ static char * do_phys_path(XString *xsp, char *xp, const char *pathl) { const char *p, *q; - int len, llen; - int savepos; - char lbuf[PATH_MAX]; + int len, llen, savepos; + char *lbuf; + lbuf = alloc(PATH_MAX, ATEMP); Xcheck(*xsp, xp); for (p = pathl; p; p = q) { while (*p == '/') @@ -1329,22 +1329,25 @@ do_phys_path(XString *xsp, char *xp, const char *pathl) xp += len; *xp = '\0'; - llen = readlink(Xstring(*xsp, xp), lbuf, sizeof(lbuf) - 1); + llen = readlink(Xstring(*xsp, xp), lbuf, PATH_MAX - 1); if (llen < 0) { /* EINVAL means it wasn't a symlink... */ - if (errno != EINVAL) - return NULL; - continue; + if (errno != EINVAL) { + xp = NULL; + goto out; + } } lbuf[llen] = '\0'; /* If absolute path, start from scratch.. */ xp = lbuf[0] == '/' ? Xstring(*xsp, xp) : Xrestpos(*xsp, xp, savepos); - if (!(xp = do_phys_path(xsp, xp, lbuf))) - return NULL; + if ((xp = do_phys_path(xsp, xp, lbuf)) == NULL) + break; } - return xp; + out: + afree(lbuf, ATEMP); + return (xp); } #ifdef USE_CHVT diff --git a/sh.h b/sh.h index 25e549e..5679196 100644 --- a/sh.h +++ b/sh.h @@ -122,9 +122,9 @@ #define __SCCSID(x) __IDSTRING(sccsid,x) #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.302 2009/05/21 14:28:35 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.303 2009/05/27 09:58:23 tg Exp $"); #endif -#define MKSH_VERSION "R38 2009/05/21" +#define MKSH_VERSION "R38 2009/05/27" #ifndef MKSH_INCLUDES_ONLY diff --git a/strlcpy.c b/strlcpy.c index 4f248aa..597005f 100644 --- a/strlcpy.c +++ b/strlcpy.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 2006, 2008 + * Copyright (c) 2006, 2008, 2009 * Thorsten Glaser * Copyright (c) 1998 Todd C. Miller * @@ -18,7 +18,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/strlcpy.c,v 1.5 2009/05/16 18:57:54 tg Rel $"); +__RCSID("$MirOS: src/bin/mksh/strlcpy.c,v 1.6 2009/05/27 09:58:24 tg Rel $"); /* * Copy src to string dst of size siz. At most siz-1 characters @@ -48,5 +48,5 @@ strlcpy(char *dst, const char *src, size_t siz) } /* count does not include NUL */ - return (s - src - 1); + return ((size_t)(s - src - 1)); }