diff --git a/SDA.c b/SDA.c index 08a7db2..b900fe8 100644 --- a/SDA.c +++ b/SDA.c @@ -15,6 +15,7 @@ ObjRef getSDA(int i, struct sda s) { } void setSDA(int point, ObjRef val, struct sda s) { + if (val == NULL) perror("Value is null"); s.sda[point] = val; } diff --git a/bigint/build/bin/testbip b/bigint/build/bin/testbip index e440237..8ff35dc 100755 Binary files a/bigint/build/bin/testbip and b/bigint/build/bin/testbip differ diff --git a/bigint/build/lib/libbigint.a b/bigint/build/lib/libbigint.a index dd462db..f13c526 100644 Binary files a/bigint/build/lib/libbigint.a and b/bigint/build/lib/libbigint.a differ diff --git a/bigint/src/libbigint.a b/bigint/src/libbigint.a index dd462db..f13c526 100644 Binary files a/bigint/src/libbigint.a and b/bigint/src/libbigint.a differ diff --git a/bigint/tst/testbip b/bigint/tst/testbip index e440237..8ff35dc 100755 Binary files a/bigint/tst/testbip and b/bigint/tst/testbip differ diff --git a/njvm.o b/njvm.o index adbcd7b..59baaa5 100644 Binary files a/njvm.o and b/njvm.o differ diff --git a/record.c b/record.c index b6345db..e67ca85 100644 --- a/record.c +++ b/record.c @@ -20,29 +20,35 @@ ObjRef newRecord(int size){ return record; } int getSize(ObjRef arr){ + if(arr == NULL) return 0; return GET_ELEMENT_COUNT(arr); } ObjRef getField(ObjRef arr, int point){ + if(arr == NULL) perror("Record is null"); if(0 > point || point > getSize(arr)){ printf("Index %i out of bounds for length %i\n",point, getSize(arr)); } return *(ObjRef *)GET_REFS_PTR(arr)[point]->data; } void setField(ObjRef arr, int point, ObjRef value){ + bool isNull = false; + if(value == NULL) isNull = true; if(0 > point || point >= getSize(arr)){ printf("Index %i out of bounds for length %i\n",point, getSize(arr)); exit(EXIT_FAILURE); } + if(arr == NULL) perror("Record is null"); if(IS_PRIMITIVE(arr)) perror("Record is a primitive"); - if(IS_PRIMITIVE(value)){ - int size = value->size; - if((GET_REFS_PTR(arr)[point] = malloc(size)) == NULL) perror("malloc"); - GET_REFS_PTR(arr)[point]->size = size; - }else{ - int size = sizeof(*value) + (GET_ELEMENT_COUNT(value) * sizeof(void *)); - if((GET_REFS_PTR(arr)[point] = malloc(size)) == NULL) perror("malloc"); - GET_REFS_PTR(arr)[point] ->size = size; + int size; + if (isNull) size = sizeof(void *); + else { + if (IS_PRIMITIVE(value)) + size = value->size; + else + size = sizeof(*value) + (GET_ELEMENT_COUNT(value) * sizeof(void *)); } + if((GET_REFS_PTR(arr)[point] = malloc(size)) == NULL) perror("malloc"); + GET_REFS_PTR(arr)[point] ->size = size; * (ObjRef *)GET_REFS_PTR(arr)[point]->data = value; } diff --git a/stack.c b/stack.c index 6925d71..34a9b91 100755 --- a/stack.c +++ b/stack.c @@ -8,9 +8,6 @@ #include #include "stackslot.c" - - - struct stack { int* size; int* current; @@ -26,11 +23,13 @@ void printStack(struct stack stack, int fp) { printf("Stack\nSize:\t\t%i\nCurrent:\t%i\n", *stack.size, *stack.current); for (int i = *stack.current -1; i >= 0; --i) { printf("%i\t",i); + if(stack.stack[i].u.objRef == NULL) printf("|NULL|"); + else if(stack.stack[i].isObjRef){ printf("|%p|", (void *)stack.stack[i].u.objRef); if(stack.stack[i].u.objRef->size == sizeof(int)) printf("(%i)",*(int *)stack.stack[i].u.objRef->data); - }else { + }else { printf("|%i|", getIntValfromStackSlot(stack.stack[i])); } if(fp == i) printf("<-\tFP\n"); diff --git a/stackslot.c b/stackslot.c index 6e28921..659a5eb 100644 --- a/stackslot.c +++ b/stackslot.c @@ -30,6 +30,7 @@ ObjRef getIntObj(int val) { } int getValFromIntObj(ObjRef iref) { + if (iref == NULL) perror("ObjRef is null"); return *(int *) iref->data; } @@ -41,6 +42,7 @@ int getIntValfromStackSlot(StackSlot s) { } void setValIntObj(ObjRef iref, int val) { + if (iref == NULL) perror("ObjRef is null"); iref->size = sizeof(int)+sizeof(ObjRef); *(int *) iref->data = val; }