Skip to content

Commit

Permalink
FIX: crash when trying to initialise multi-dimension struct value
Browse files Browse the repository at this point in the history
  • Loading branch information
Oldes committed Sep 11, 2023
1 parent 9fffc0b commit c7d3281
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/core/t-struct.c
Original file line number Diff line number Diff line change
Expand Up @@ -755,12 +755,15 @@ static REBOOL parse_field_type(struct Struct_Field *field, REBVAL *spec, REBVAL
init = blk++;
#endif
if (field->array) {
if (IS_INTEGER(init)) { /* interpreted as a C pointer */
void *ptr = (void *)VAL_INT64(init);

/* assuming it's an valid pointer and holding enough space */
memcpy(SERIES_SKIP(VAL_STRUCT_DATA_BIN(out), (REBCNT)offset), ptr, field->size * field->dimension);
} else if (IS_BLOCK(init)) {
// O: It is probably not a good idea to let access to C pointers!
// https://github.com/Oldes/Rebol-issues/issues/2567
// if (IS_INTEGER(init)) { /* interpreted as a C pointer */
// void *ptr = (void *)VAL_INT64(init);
//
// /* assuming it's an valid pointer and holding enough space */
// memcpy(SERIES_SKIP(VAL_STRUCT_DATA_BIN(out), (REBCNT)offset), ptr, field->size * field->dimension);
// } else
if (IS_BLOCK(init)) {
REBCNT n = 0;

if (VAL_LEN(init) != field->dimension) {
Expand Down
6 changes: 6 additions & 0 deletions src/tests/units/struct-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ Rebol [
error? e: try [make struct! [ a: [uint8!] probe random 100 ]]
e/id = 'invalid-type
]
--test-- "Invalid array type initialisation"
;@@ https://github.com/Oldes/Rebol-issues/issues/2567
--assert all [
error? e: try [ make struct! [a: [int8! [2]] 1] ] ;- No crash!
e/id = 'expect-val
]
===end-group===


Expand Down

0 comments on commit c7d3281

Please sign in to comment.