Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Primitive reference type crashes corto_value_binaryOp #689

Open
SanderMertens opened this issue Jul 13, 2018 · 2 comments
Open

Primitive reference type crashes corto_value_binaryOp #689

SanderMertens opened this issue Jul 13, 2018 · 2 comments
Labels

Comments

@SanderMertens
Copy link
Member

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
@SanderMertens
Copy link
Member Author

SanderMertens commented Jul 13, 2018

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*).

@SanderMertens
Copy link
Member Author

Type size calculation is wrong too. The primitive type size is used, not the size of a reference (sizeof(corto_object)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant