From 362bfb0221928d141969f7e2048399bd4637aff6 Mon Sep 17 00:00:00 2001 From: Eric Buehler <65165915+EricLBuehler@users.noreply.github.com> Date: Mon, 5 Dec 2022 20:08:56 -0500 Subject: [PATCH] Memory undefined behavior and other bug fixes --- object/floatobject.cpp | 2 ++ object/funcobject.cpp | 2 +- object/stringobject.cpp | 2 +- object/types.cpp | 3 +++ 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/object/floatobject.cpp b/object/floatobject.cpp index feaaf224..2348749f 100644 --- a/object/floatobject.cpp +++ b/object/floatobject.cpp @@ -114,11 +114,13 @@ object* float_mod(object* self, object* other){ if (otherfloat==NULL || !object_istype(otherfloat->type, &FloatType)){ return NULL; } + if (CAST_FLOAT(otherfloat)->val==0){ vm_add_err(&ZeroDivisionError, vm, "Modulus by zero"); FPLDECREF(otherfloat); return NULL; } + double res=fmod(CAST_FLOAT(self)->val,CAST_FLOAT(otherfloat)->val); FPLDECREF(otherfloat); int ires=(int)res; diff --git a/object/funcobject.cpp b/object/funcobject.cpp index 4352a28c..c5989e6d 100644 --- a/object/funcobject.cpp +++ b/object/funcobject.cpp @@ -82,6 +82,7 @@ object* func_call(object* self, object* args, object* kwargs){ uint32_t argc=CAST_LIST(args)->size+CAST_DICT(kwargs)->val->size(); uint32_t posargc=CAST_LIST(args)->size; uint32_t kwargc=argc-posargc; + *CAST_FUNC(self)->ip=0; add_callframe(vm->callstack, tuple_index_int(list_index_int(CAST_CODE(CAST_FUNC(self)->code)->co_lines, 0),2), CAST_STRING(CAST_FUNC(self)->name)->val, CAST_FUNC(self)->code, self, CAST_FUNC(self)->ip); @@ -94,7 +95,6 @@ object* func_call(object* self, object* args, object* kwargs){ vm->globals=CAST_FUNC(self)->globals; vm->global_annotations=CAST_FUNC(self)->global_anno; - int flags=CAST_FUNC(self)->flags; if (flags!=FUNC_STAR && CAST_FUNC(self)->argc-CAST_LIST(CAST_FUNC(self)->kwargs)->size>posargc \ diff --git a/object/stringobject.cpp b/object/stringobject.cpp index 1c6930cf..a06210a8 100644 --- a/object/stringobject.cpp +++ b/object/stringobject.cpp @@ -222,7 +222,7 @@ object* str_repr(object* self){ object* str_str(object* self){ FPLINCREF(self); - return self; //str_new_fromstr(new string((*CAST_STRING(self)->val))); + return self; } object* str_bool(object* self){ diff --git a/object/types.cpp b/object/types.cpp index a4ef228f..6c8b3888 100644 --- a/object/types.cpp +++ b/object/types.cpp @@ -914,6 +914,7 @@ void setup_func_type(){ + void none_del(object* self); object* none_repr(object* self); object* none_bool(object* self); @@ -997,6 +998,8 @@ void setup_none_type(){ } + + void builtin_del(object* self); object* builtin_repr_slot(object* self); object* builtin_cmp(object* self, object* other, uint8_t type);