Skip to content

Commit

Permalink
Correct string size for classes and strings
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason2605 committed Apr 10, 2020
1 parent 9ffc7e1 commit 34391f2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions c/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ char *setToString(Value value) {

char *classToString(Value value) {
ObjClass *klass = AS_CLASS(value);
char *classString = malloc(sizeof(char) * (klass->name->length + 6));
char *classString = malloc(sizeof(char) * (klass->name->length + 7));
memcpy(classString, "<cls ", 5);
memcpy(classString + 5, klass->name->chars, klass->name->length);
memcpy(classString + 5 + klass->name->length, ">", 1);
Expand All @@ -429,7 +429,7 @@ char *classToString(Value value) {

char *instanceToString(Value value) {
ObjInstance *instance = AS_INSTANCE(value);
char *instanceString = malloc(sizeof(char) * (instance->klass->name->length + 11));
char *instanceString = malloc(sizeof(char) * (instance->klass->name->length + 12));
memcpy(instanceString, "<", 1);
memcpy(instanceString + 1, instance->klass->name->chars, instance->klass->name->length);
memcpy(instanceString + 1 + instance->klass->name->length, " instance>", 10);
Expand Down

0 comments on commit 34391f2

Please sign in to comment.