corto
corto copied to clipboard
Primitive reference type crashes corto_value_binaryOp
When the following cortoscript code is parsed:
int ref_i32: width_32, reference: true
struct Point {
x, y: ref_i32
}
ref_i32 a, b: 10
Point p = {a, b}
it crashes with this stack trace:
==11195== Invalid read of size 4
==11195== at 0x4EB591F: _corto_assert_object (bootstrap.c:1495)
==11195== by 0x4E8DF5A: corto_set_ref (object.c:5372)
==11195== by 0x4EAF2F1: corto_intern_binaryOp (operator.c:484)
==11195== by 0x4EAF5EA: corto_ptr_binaryOp (operator.c:518)
==11195== by 0x4EB2F3B: corto_value_binaryOp (value.c:1012)
==11195== by 0x4EB7586: corto_rw_set_value (rw.c:804)
==11195== by 0x6A4E4C8: _corto_script_ast_Initializer_apply (Initializer.cpp:38)
==11195== by 0x6C7EE1C: _corto_script_declare_Visitor_visitDeclaration (Visitor.c:301)
==11195== by 0x6A5A9B2: _corto_script_ast_Visitor_visit (Visitor.cpp:19)
==11195== by 0x6A5B8BD: _corto_script_ast_Visitor_visitScope_v (Visitor.cpp:98)
==11195== by 0x6C7F326: _corto_script_declare_Visitor_visitScope (Visitor.c:372)
==11195== by 0x6A5A826: _corto_script_ast_Visitor_visit (Visitor.cpp:14)
==11195== Address 0xfffffffffffffff2 is not stack'd, malloc'd or (recently) free'd
Code generators also do not properly handle the ref_i32
type. The C type code generator generates the following code:
typedef int32_t test_i32_ref;
This should be:
typedef int32_t *test_i32_ref;
Additionally the generated APIs also generate incorrect types (int32_t
instead of int32_t*
).
Type size calculation is wrong too. The primitive type size is used, not the size of a reference (sizeof(corto_object)
).