fix remaining signed int nonsense I am aware of

This commit is contained in:
tg 2013-04-26 19:10:58 +00:00
parent 79a083baaa
commit 75a4809a3a
2 changed files with 13 additions and 9 deletions

4
expr.c
View File

@ -23,7 +23,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.69 2013/04/14 13:36:50 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.70 2013/04/26 19:10:58 tg Exp $");
/* the order of these enums is constrained by the order of opinfo[] */
enum token {
@ -155,7 +155,7 @@ typedef struct expr_state {
/* token from token() */
enum token tok;
/* don't do assignments (for ?:, &&, ||) */
short noassign;
uint8_t noassign;
/* evaluating an $(()) expression? */
bool arith;
/* unsigned arithmetic calculation */

18
misc.c
View File

@ -30,7 +30,7 @@
#include <grp.h>
#endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.208 2013/04/01 02:37:51 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.209 2013/04/26 19:10:58 tg Exp $");
#define KSH_CHVT_FLAG
#ifdef MKSH_SMALL
@ -472,9 +472,11 @@ int
getn(const char *s, int *ai)
{
char c;
unsigned int i = 0;
mksh_ari_u num;
bool neg = false;
num.u = 0;
do {
c = *s++;
} while (ksh_isspace(c));
@ -492,18 +494,20 @@ getn(const char *s, int *ai)
if (!ksh_isdigit(c))
/* not numeric */
return (0);
if (i > 214748364U)
if (num.u > 214748364U)
/* overflow on multiplication */
return (0);
i = i * 10U + (unsigned int)(c - '0');
/* now: i <= 2147483649U */
num.u = num.u * 10U + (unsigned int)(c - '0');
/* now: num.u <= 2147483649U */
} while ((c = *s++));
if (i > (neg ? 2147483648U : 2147483647U))
if (num.u > (neg ? 2147483648U : 2147483647U))
/* overflow for signed 32-bit int */
return (0);
*ai = neg ? -(int)i : (int)i;
if (neg)
num.u = -num.u;
*ai = num.i;
return (1);
}