From 72eca4a15fc3842319d85097f2b1173da96950bf Mon Sep 17 00:00:00 2001 From: William Bell <62452284+Ugric@users.noreply.github.com> Date: Mon, 1 Dec 2025 01:35:20 +0000 Subject: [PATCH] fix null + 1 causing seg fault --- src/runtime/runtime.c | 28 ++++++++++++++++------------ tests/null_plus_one.ar | 1 + 2 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 tests/null_plus_one.ar diff --git a/src/runtime/runtime.c b/src/runtime/runtime.c index 4489cb3..997148b 100644 --- a/src/runtime/runtime.c +++ b/src/runtime/runtime.c @@ -100,12 +100,13 @@ ArgonObject *ARGON_ADDITION_FUNCTION(size_t argc, ArgonObject **argv, } ArgonObject *output = argv[0]; for (size_t i = 1; i < argc; i++) { + ArgonObject *object_class = get_builtin_field(output, __class__); ArgonObject *object__add__ = get_builtin_field_for_class( - get_builtin_field(output, __class__), __add__, output); + object_class, __add__, output); if (!object__add__) { - ArgonObject *cls___name__ = get_builtin_field(output, __name__); + ArgonObject *cls___name__ = get_builtin_field(object_class, __name__); *err = create_err(0, 0, 0, "", "Runtime Error", - "Object '%.*s' is missing __add__ method", + "Object of type '%.*s' is missing __add__ method", (int)cls___name__->value.as_str->length, cls___name__->value.as_str->data); return ARGON_NULL; @@ -126,12 +127,13 @@ ArgonObject *ARGON_SUBTRACTION_FUNCTION(size_t argc, ArgonObject **argv, } ArgonObject *output = argv[0]; for (size_t i = 1; i < argc; i++) { + ArgonObject *object_class = get_builtin_field(output, __class__); ArgonObject *function__subtract__ = get_builtin_field_for_class( - get_builtin_field(output, __class__), __subtract__, output); + object_class, __subtract__, output); if (!function__subtract__) { - ArgonObject *cls___name__ = get_builtin_field(output, __name__); + ArgonObject *cls___name__ = get_builtin_field(object_class, __name__); *err = create_err(0, 0, 0, "", "Runtime Error", - "Object '%.*s' is missing __subtract__ method", + "Object of type '%.*s' is missing __subtract__ method", (int)cls___name__->value.as_str->length, cls___name__->value.as_str->data); return ARGON_NULL; @@ -152,12 +154,13 @@ ArgonObject *ARGON_MULTIPLY_FUNCTION(size_t argc, ArgonObject **argv, } ArgonObject *output = argv[0]; for (size_t i = 1; i < argc; i++) { + ArgonObject *object_class = get_builtin_field(output, __class__); ArgonObject *function__multiply__ = get_builtin_field_for_class( - get_builtin_field(output, __class__), __multiply__, output); + object_class, __multiply__, output); if (!function__multiply__) { - ArgonObject *cls___name__ = get_builtin_field(output, __name__); + ArgonObject *cls___name__ = get_builtin_field(object_class, __name__); *err = create_err(0, 0, 0, "", "Runtime Error", - "Object '%.*s' is missing __multiply__ method", + "Object of type '%.*s' is missing __multiply__ method", (int)cls___name__->value.as_str->length, cls___name__->value.as_str->data); return ARGON_NULL; @@ -177,12 +180,13 @@ ArgonObject *ARGON_DIVIDE_FUNCTION(size_t argc, ArgonObject **argv, ArErr *err, } ArgonObject *output = argv[0]; for (size_t i = 1; i < argc; i++) { + ArgonObject *object_class = get_builtin_field(output, __class__); ArgonObject *function___divide__ = get_builtin_field_for_class( - get_builtin_field(output, __class__), __divide__, output); + object_class, __divide__, output); if (!function___divide__) { - ArgonObject *cls___name__ = get_builtin_field(output, __name__); + ArgonObject *cls___name__ = get_builtin_field(object_class, __name__); *err = create_err(0, 0, 0, "", "Runtime Error", - "Object '%.*s' is missing __divide__ method", + "Object of type '%.*s' is missing __divide__ method", (int)cls___name__->value.as_str->length, cls___name__->value.as_str->data); return ARGON_NULL; diff --git a/tests/null_plus_one.ar b/tests/null_plus_one.ar new file mode 100644 index 0000000..6591f2f --- /dev/null +++ b/tests/null_plus_one.ar @@ -0,0 +1 @@ +null+1 \ No newline at end of file