Skip to content

Commit c7d3281

Browse files
committed
FIX: crash when trying to initialise multi-dimension struct value
resolves: Oldes/Rebol-issues#2567
1 parent 9fffc0b commit c7d3281

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

src/core/t-struct.c

+9-6
Original file line numberDiff line numberDiff line change
@@ -755,12 +755,15 @@ static REBOOL parse_field_type(struct Struct_Field *field, REBVAL *spec, REBVAL
755755
init = blk++;
756756
#endif
757757
if (field->array) {
758-
if (IS_INTEGER(init)) { /* interpreted as a C pointer */
759-
void *ptr = (void *)VAL_INT64(init);
760-
761-
/* assuming it's an valid pointer and holding enough space */
762-
memcpy(SERIES_SKIP(VAL_STRUCT_DATA_BIN(out), (REBCNT)offset), ptr, field->size * field->dimension);
763-
} else if (IS_BLOCK(init)) {
758+
// O: It is probably not a good idea to let access to C pointers!
759+
// https://github.com/Oldes/Rebol-issues/issues/2567
760+
// if (IS_INTEGER(init)) { /* interpreted as a C pointer */
761+
// void *ptr = (void *)VAL_INT64(init);
762+
//
763+
// /* assuming it's an valid pointer and holding enough space */
764+
// memcpy(SERIES_SKIP(VAL_STRUCT_DATA_BIN(out), (REBCNT)offset), ptr, field->size * field->dimension);
765+
// } else
766+
if (IS_BLOCK(init)) {
764767
REBCNT n = 0;
765768

766769
if (VAL_LEN(init) != field->dimension) {

src/tests/units/struct-test.r3

+6
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ Rebol [
154154
error? e: try [make struct! [ a: [uint8!] probe random 100 ]]
155155
e/id = 'invalid-type
156156
]
157+
--test-- "Invalid array type initialisation"
158+
;@@ https://github.com/Oldes/Rebol-issues/issues/2567
159+
--assert all [
160+
error? e: try [ make struct! [a: [int8! [2]] 1] ] ;- No crash!
161+
e/id = 'expect-val
162+
]
157163
===end-group===
158164

159165

0 commit comments

Comments
 (0)