I give up on writing (1 << 31) in any form.
Now we just use 0x80000000UL and cast that to mksh_uari_t and, if required, that to mksh_ari_t afterwards.
This commit is contained in:
parent
ac18ec3752
commit
9646c98356
23
expr.c
23
expr.c
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.55 2012/03/31 17:29:59 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.56 2012/03/31 17:52:33 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 {
|
||||||
@ -367,12 +367,19 @@ evalexpr(Expr_state *es, int prec)
|
|||||||
case O_DIV:
|
case O_DIV:
|
||||||
case O_DIVASN:
|
case O_DIVASN:
|
||||||
#if !HAVE_SILENT_IDIVWRAPV
|
#if !HAVE_SILENT_IDIVWRAPV
|
||||||
if (!es->natural && vr->val.i == -1 &&
|
/*
|
||||||
vl->val.i == ((mksh_ari_t)-2147483648)) {
|
* we are doing the comparisons here for the
|
||||||
|
* signed arithmetics (!es->natural) case,
|
||||||
|
* but the exact value checks and the bypass
|
||||||
|
* case assignments are done unsignedly as
|
||||||
|
* several compilers bitch around otherwise
|
||||||
|
*/
|
||||||
|
if (!es->natural &&
|
||||||
|
vl->val.u == (mksh_uari_t)0x80000000UL &&
|
||||||
|
vr->val.u == (mksh_uari_t)0xFFFFFFFFUL) {
|
||||||
/* -2147483648 / -1 = 2147483648 */
|
/* -2147483648 / -1 = 2147483648 */
|
||||||
/* this ^ is really (1 << 31) though */
|
/* this ^ is really (1 << 31) though */
|
||||||
/* 80000000 / FFFFFFFF = 80000000 */
|
res = (mksh_ari_t)(mksh_uari_t)0x80000000UL;
|
||||||
res = ((mksh_ari_t)-2147483648);
|
|
||||||
} else
|
} else
|
||||||
#endif
|
#endif
|
||||||
res = bivui(vl, /, vr);
|
res = bivui(vl, /, vr);
|
||||||
@ -380,8 +387,10 @@ evalexpr(Expr_state *es, int prec)
|
|||||||
case O_MOD:
|
case O_MOD:
|
||||||
case O_MODASN:
|
case O_MODASN:
|
||||||
#if !HAVE_SILENT_IDIVWRAPV
|
#if !HAVE_SILENT_IDIVWRAPV
|
||||||
if (!es->natural && vr->val.i == -1 &&
|
/* see O_DIV / O_DIVASN for the reason behind this */
|
||||||
vl->val.i == ((mksh_ari_t)-2147483648)) {
|
if (!es->natural &&
|
||||||
|
vl->val.u == (mksh_uari_t)0x80000000UL &&
|
||||||
|
vr->val.u == (mksh_uari_t)0xFFFFFFFFUL) {
|
||||||
/* -2147483648 % -1 = 0 */
|
/* -2147483648 % -1 = 0 */
|
||||||
res = 0;
|
res = 0;
|
||||||
} else
|
} else
|
||||||
|
Loading…
Reference in New Issue
Block a user