rewrite some code to avoid gcc 4.8 complaining

This commit is contained in:
tg 2012-10-03 16:16:15 +00:00
parent b55d9870e3
commit c39bfe09ee
3 changed files with 18 additions and 10 deletions

View File

@ -38,7 +38,7 @@
#endif #endif
#endif #endif
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.224 2012/10/03 15:13:31 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.225 2012/10/03 16:16:12 tg Exp $");
#if HAVE_KILLPG #if HAVE_KILLPG
/* /*
@ -976,7 +976,9 @@ c_typeset_vardump(struct tbl *vp, uint32_t flag, int thing, bool pflag,
* Only report first 'element' of an array with * Only report first 'element' of an array with
* no set elements. * no set elements.
*/ */
} while (any_set && (vp = vp->u.array)); if (!any_set)
return;
} while ((vp = vp->u.array));
} }
int int

10
sh.h
View File

@ -157,7 +157,7 @@
#endif #endif
#ifdef EXTERN #ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.590 2012/10/03 15:55:37 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/sh.h,v 1.591 2012/10/03 16:16:13 tg Exp $");
#endif #endif
#define MKSH_VERSION "R40 2012/09/07" #define MKSH_VERSION "R40 2012/09/07"
@ -1559,9 +1559,11 @@ EXTERN mksh_ari_t histsize; /* history size */
/* user and system time of last j_waitjed job */ /* user and system time of last j_waitjed job */
EXTERN struct timeval j_usrtime, j_systime; EXTERN struct timeval j_usrtime, j_systime;
#define notoktomul(fac1, fac2) (((fac1) != 0) && ((fac2) != 0) && \ #define notok2mul(max, val, c) (((val) != 0) && ((c) != 0) && \
((SIZE_MAX / (fac2)) < (fac1))) (((max) / (c)) < (val)))
#define notoktoadd(val, cnst) ((val) > (SIZE_MAX - (cnst))) #define notok2add(max, val, c) ((val) > ((max) - (c)))
#define notoktomul(val, cnst) notok2mul(SIZE_MAX, (val), (cnst))
#define notoktoadd(val, cnst) notok2add(SIZE_MAX, (val), (cnst))
#define checkoktoadd(val, cnst) do { \ #define checkoktoadd(val, cnst) do { \
if (notoktoadd((val), (cnst))) \ if (notoktoadd((val), (cnst))) \
internal_errorf(Tintovfl, (size_t)(val), \ internal_errorf(Tintovfl, (size_t)(val), \

12
shf.c
View File

@ -24,7 +24,7 @@
#include "sh.h" #include "sh.h"
__RCSID("$MirOS: src/bin/mksh/shf.c,v 1.46 2012/07/01 15:55:00 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/shf.c,v 1.47 2012/10/03 16:16:15 tg Exp $");
/* flags to shf_emptybuf() */ /* flags to shf_emptybuf() */
#define EB_READSW 0x01 /* about to switch to reading */ #define EB_READSW 0x01 /* about to switch to reading */
@ -842,12 +842,16 @@ shf_vfprintf(struct shf *shf, const char *fmt, va_list args)
continue; continue;
} }
if (ksh_isdigit(c)) { if (ksh_isdigit(c)) {
bool overflowed = false;
tmp = c - '0'; tmp = c - '0';
while (c = *fmt++, ksh_isdigit(c)) while (c = *fmt++, ksh_isdigit(c)) {
if (notok2mul(2147483647, tmp, 10))
overflowed = true;
tmp = tmp * 10 + c - '0'; tmp = tmp * 10 + c - '0';
}
--fmt; --fmt;
if (tmp < 0) if (overflowed)
/* overflow? */
tmp = 0; tmp = 0;
if (flags & FL_DOT) if (flags & FL_DOT)
precision = tmp; precision = tmp;