Skip to content

Commit d07af99

Browse files
committed
CHANGE: don't allow to conversion from logic! to integer!, money! and percent!
related to: Oldes/Rebol-issues#1018
1 parent bf649c2 commit d07af99

File tree

3 files changed

+67
-5
lines changed

3 files changed

+67
-5
lines changed

src/core/t-decimal.c

+5-2
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ REBOOL almost_equal(REBDEC a, REBDEC b, REBCNT max_diff) {
356356
goto setDec;
357357

358358
case REB_LOGIC:
359+
if (action != A_MAKE) goto err_make;
359360
d1 = VAL_LOGIC(val) ? 1.0 : 0.0;
360361
goto setDec;
361362

@@ -377,7 +378,7 @@ REBOOL almost_equal(REBDEC a, REBDEC b, REBCNT max_diff) {
377378
if (type == REB_PERCENT) break;
378379
goto setDec;
379380
}
380-
Trap_Make(type, val);
381+
goto err_make;
381382
}
382383

383384
case REB_BINARY:
@@ -413,8 +414,10 @@ REBOOL almost_equal(REBDEC a, REBDEC b, REBCNT max_diff) {
413414
exp--, d1 *= 10.0, Check_Overflow(d1);
414415
while (exp <= -1)
415416
exp++, d1 /= 10.0;
416-
} else
417+
} else {
418+
err_make:
417419
Trap_Make(type, val);
420+
}
418421
}
419422

420423
if (type == REB_PERCENT) d1 /= 100.0;

src/core/t-money.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@
218218
const REBYTE *end;
219219
str = Qualify_String(arg, 36, 0, FALSE);
220220
VAL_DECI(D_RET) = string_to_deci(str, &end);
221-
if (end == str || *end != 0) Trap_Make(REB_MONEY, arg);
221+
if (end == str || *end != 0) goto err;
222222
break;
223223
}
224224

@@ -228,8 +228,9 @@
228228
break;
229229

230230
case REB_LOGIC:
231+
if(action != A_MAKE) goto err;
231232
equal = !VAL_LOGIC(arg);
232-
// case REB_NONE: // 'equal defaults to 1
233+
// case REB_NONE: // 'equal defaults to 1 // removed by design
233234
VAL_DECI(D_RET) = int_to_deci(equal ? 0 : 1);
234235
break;
235236

src/tests/units/make-test.r3

+59-1
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,44 @@ Rebol [
4747
===end-group===
4848

4949

50-
===start-group=== "make decimal!"
50+
===start-group=== "make/to integer"
51+
--test-- "to integer! logic!"
52+
;@@ https://github.com/Oldes/Rebol-issues/issues/1018
53+
--assert all [
54+
error? e: try [to integer! true]
55+
e/id = 'bad-make-arg
56+
]
57+
--assert all [
58+
error? e: try [to integer! false]
59+
e/id = 'bad-make-arg
60+
]
61+
--test-- "make integer! logic!"
62+
;@@ https://github.com/Oldes/Rebol-issues/issues/1018
63+
--assert 1 = make integer! true
64+
--assert 0 = make integer! false
65+
--assert 1 = make 42 true
66+
--assert 0 = make 42 false
67+
--assert error? try [to integer! true]
68+
--assert error? try [to integer! false]
69+
70+
===end-group===
71+
72+
===start-group=== "make/to decimal!"
5173
--test-- "to decimal! issue!"
5274
;@@ https://github.com/Oldes/Rebol-issues/issues/1130
5375
--assert all [
5476
error? e: try [to decimal! #FF]
5577
e/id = 'bad-make-arg
5678
]
79+
--test-- "make/to decimal! logic!"
80+
;@@ https://github.com/Oldes/Rebol-issues/issues/1018
81+
--assert 1.0 = make decimal! true
82+
--assert 0.0 = make decimal! false
83+
--assert 1.0 = make 0.0 true
84+
--assert 0.0 = make 0.0 false
85+
--assert error? try [to decimal! true]
86+
--assert error? try [to decimal! false]
87+
5788
===end-group===
5889

5990

@@ -64,6 +95,32 @@ Rebol [
6495
error? e: try [to money! #FF]
6596
e/id = 'bad-make-arg
6697
]
98+
--test-- "make/to money! logic!"
99+
;@@ https://github.com/Oldes/Rebol-issues/issues/1018
100+
--assert $1 = make money! true
101+
--assert $0 = make money! false
102+
--assert $1 = make $111 true
103+
--assert $0 = make $111 false
104+
--assert error? try [to money! true]
105+
--assert error? try [to money! false]
106+
===end-group===
107+
108+
109+
===start-group=== "make percent!"
110+
--test-- "to percent! issue!"
111+
;@@ https://github.com/Oldes/Rebol-issues/issues/1130
112+
--assert all [
113+
error? e: try [to percent! #FF]
114+
e/id = 'bad-make-arg
115+
]
116+
--test-- "make/to percent! logic!"
117+
;@@ https://github.com/Oldes/Rebol-issues/issues/1018
118+
--assert 100% = make percent! true
119+
--assert 0% = make percent! false
120+
--assert 100% = make 50% true
121+
--assert 0% = make 50% false
122+
--assert error? try [to percent! true]
123+
--assert error? try [to percent! false]
67124
===end-group===
68125

69126

@@ -85,6 +142,7 @@ Rebol [
85142

86143
===start-group=== "make special"
87144
--test-- "make types from none!"
145+
;@@ https://github.com/Oldes/Rebol-issues/issues/1018
88146
;@@ https://github.com/Oldes/Rebol-issues/issues/1041
89147
--assert error? try [make end! none]
90148
--assert not error? try [make unset! none]

0 commit comments

Comments
 (0)