Skip to content

Commit

Permalink
Memory undefined behavior and other bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
EricLBuehler authored Dec 6, 2022
1 parent 4a604c2 commit 362bfb0
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 2 deletions.
2 changes: 2 additions & 0 deletions object/floatobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion object/funcobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 \
Expand Down
2 changes: 1 addition & 1 deletion object/stringobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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){
Expand Down
3 changes: 3 additions & 0 deletions object/types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -914,6 +914,7 @@ void setup_func_type(){




void none_del(object* self);
object* none_repr(object* self);
object* none_bool(object* self);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 362bfb0

Please sign in to comment.