Skip to content

Commit 3224ad2

Browse files
committed
Replace code with undefined behaviour.
1 parent 15892da commit 3224ad2

File tree

2 files changed

+23
-13
lines changed

2 files changed

+23
-13
lines changed

src/core/t-integer.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,11 @@
163163

164164
case A_DIVIDE:
165165
if (arg == 0) Trap0(RE_ZERO_DIVIDE);
166-
if (num < - MAX_I64 && arg == -1) Trap0(RE_OVERFLOW);
166+
if(arg == -1) {
167+
if(num < - MAX_I64) Trap0(RE_OVERFLOW);
168+
num = - num;
169+
break;
170+
}
167171
if (num % arg == 0) {
168172
num = num / arg;
169173
break;

src/core/t-pair.c

+18-12
Original file line numberDiff line numberDiff line change
@@ -206,26 +206,32 @@
206206
switch (action) {
207207

208208
case A_ADD:
209-
x1 += x2;
210-
y1 += y2;
209+
x1 = (REBCNT) x1 + (REBCNT) x2;
210+
y1 = (REBCNT) y1 + (REBCNT) y2;
211211
goto setPair;
212212

213213
case A_SUBTRACT:
214-
x1 -= x2;
215-
y1 -= y2;
214+
x1 = (REBCNT) x1 - (REBCNT) x2;
215+
y1 = (REBCNT) y1 - (REBCNT) y2;
216216
goto setPair;
217217

218218
case A_MULTIPLY:
219-
x1 *= x2;
220-
y1 *= y2;
219+
x1 = (REBCNT) x1 * (REBCNT) x2;
220+
y1 = (REBCNT) y1 * (REBCNT) y2;
221221
goto setPair;
222222

223223
case A_DIVIDE:
224224
case A_REMAINDER:
225225
if (x2 == 0 || y2 == 0) Trap0(RE_ZERO_DIVIDE);
226226
if (action == A_DIVIDE) {
227-
x1 /= x2;
228-
y1 /= y2;
227+
if(x2 == -1)
228+
x1 = - (REBCNT) x1;
229+
else
230+
x1 /= x2;
231+
if(y2 == -1)
232+
y1 = - (REBCNT) y1;
233+
else
234+
y1 /= y2;
229235
}
230236
else {
231237
x1 = (REBD32)fmod(x1, x2);
@@ -247,8 +253,8 @@
247253
DECIDE((x1 & 1) == 0 && (y1 & 1) == 0);
248254
#endif
249255
case A_NEGATE:
250-
x1 = -x1;
251-
y1 = -y1;
256+
x1 = - (REBCNT) x1;
257+
y1 = - (REBCNT) y1;
252258
goto setPair;
253259
#ifdef temp
254260
case A_COMPLEMENT:
@@ -257,8 +263,8 @@
257263
goto setPair;
258264
#endif
259265
case A_ABSOLUTE:
260-
if (x1 < 0) x1 = -x1;
261-
if (y1 < 0) y1 = -y1;
266+
if (x1 < 0) x1 = - (REBCNT) x1;
267+
if (y1 < 0) y1 = - (REBCNT) y1;
262268
goto setPair;
263269

264270
case A_ROUND:

0 commit comments

Comments
 (0)