fix remaining signed int nonsense I am aware of
This commit is contained in:
parent
79a083baaa
commit
75a4809a3a
4
expr.c
4
expr.c
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#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[] */
|
/* the order of these enums is constrained by the order of opinfo[] */
|
||||||
enum token {
|
enum token {
|
||||||
@ -155,7 +155,7 @@ typedef struct expr_state {
|
|||||||
/* token from token() */
|
/* token from token() */
|
||||||
enum token tok;
|
enum token tok;
|
||||||
/* don't do assignments (for ?:, &&, ||) */
|
/* don't do assignments (for ?:, &&, ||) */
|
||||||
short noassign;
|
uint8_t noassign;
|
||||||
/* evaluating an $(()) expression? */
|
/* evaluating an $(()) expression? */
|
||||||
bool arith;
|
bool arith;
|
||||||
/* unsigned arithmetic calculation */
|
/* unsigned arithmetic calculation */
|
||||||
|
18
misc.c
18
misc.c
@ -30,7 +30,7 @@
|
|||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#endif
|
#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
|
#define KSH_CHVT_FLAG
|
||||||
#ifdef MKSH_SMALL
|
#ifdef MKSH_SMALL
|
||||||
@ -472,9 +472,11 @@ int
|
|||||||
getn(const char *s, int *ai)
|
getn(const char *s, int *ai)
|
||||||
{
|
{
|
||||||
char c;
|
char c;
|
||||||
unsigned int i = 0;
|
mksh_ari_u num;
|
||||||
bool neg = false;
|
bool neg = false;
|
||||||
|
|
||||||
|
num.u = 0;
|
||||||
|
|
||||||
do {
|
do {
|
||||||
c = *s++;
|
c = *s++;
|
||||||
} while (ksh_isspace(c));
|
} while (ksh_isspace(c));
|
||||||
@ -492,18 +494,20 @@ getn(const char *s, int *ai)
|
|||||||
if (!ksh_isdigit(c))
|
if (!ksh_isdigit(c))
|
||||||
/* not numeric */
|
/* not numeric */
|
||||||
return (0);
|
return (0);
|
||||||
if (i > 214748364U)
|
if (num.u > 214748364U)
|
||||||
/* overflow on multiplication */
|
/* overflow on multiplication */
|
||||||
return (0);
|
return (0);
|
||||||
i = i * 10U + (unsigned int)(c - '0');
|
num.u = num.u * 10U + (unsigned int)(c - '0');
|
||||||
/* now: i <= 2147483649U */
|
/* now: num.u <= 2147483649U */
|
||||||
} while ((c = *s++));
|
} while ((c = *s++));
|
||||||
|
|
||||||
if (i > (neg ? 2147483648U : 2147483647U))
|
if (num.u > (neg ? 2147483648U : 2147483647U))
|
||||||
/* overflow for signed 32-bit int */
|
/* overflow for signed 32-bit int */
|
||||||
return (0);
|
return (0);
|
||||||
|
|
||||||
*ai = neg ? -(int)i : (int)i;
|
if (neg)
|
||||||
|
num.u = -num.u;
|
||||||
|
*ai = num.i;
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user