From 4b0f2c5927f7e33fbb38b66466265394efa83b97 Mon Sep 17 00:00:00 2001 From: Patrick Soquet Date: Mon, 18 Jun 2018 10:14:02 +0200 Subject: [PATCH] XS: fix issue #62 --- xs/sources/xsRun.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/xs/sources/xsRun.c b/xs/sources/xsRun.c index 08f74c5de3..6eddc3b41b 100644 --- a/xs/sources/xsRun.c +++ b/xs/sources/xsRun.c @@ -2605,11 +2605,16 @@ void fxRunID(txMachine* the, txSlot* generator, txID id) if (slot->kind == mxStack->kind) { if (mxStack->kind == XS_INTEGER_KIND) { #if __has_builtin(__builtin_add_overflow) - if (__builtin_add_overflow(slot->value.integer, mxStack->value.integer, &slot->value.integer)) { + variable = mxStack; + mxPushKind(XS_INTEGER_KIND); + if (__builtin_add_overflow(slot->value.integer, variable->value.integer, &mxStack->value.integer)) { fxToNumber(the, slot); - fxToNumber(the, mxStack); - slot->value.number += mxStack->value.number; + fxToNumber(the, variable); + slot->value.number += variable->value.number; } + else + slot->value.integer = mxStack->value.integer; + mxStack++; #else txInteger a = slot->value.integer; txInteger b = mxStack->value.integer; @@ -2662,13 +2667,27 @@ void fxRunID(txMachine* the, txSlot* generator, txID id) if (slot->kind == mxStack->kind) { if (slot->kind == XS_INTEGER_KIND) { #if __has_builtin(__builtin_sub_overflow) - if (__builtin_sub_overflow(slot->value.integer, mxStack->value.integer, &slot->value.integer)) { + variable = mxStack; + mxPushKind(XS_INTEGER_KIND); + if (__builtin_sub_overflow(slot->value.integer, variable->value.integer, &mxStack->value.integer)) { + fxToNumber(the, slot); + fxToNumber(the, variable); + slot->value.number -= variable->value.number; + } + else + slot->value.integer = mxStack->value.integer; + mxStack++; + #else + txInteger a = slot->value.integer; + txInteger b = -mxStack->value.integer; + txInteger c = a + b; + if (((a ^ c) & (b ^ c)) < 0) { fxToNumber(the, slot); fxToNumber(the, mxStack); slot->value.number -= mxStack->value.number; } - #else - slot->value.integer -= mxStack->value.integer; // @@ overflow? + else + slot->value.integer = c; #endif } else if (slot->kind == XS_NUMBER_KIND)