Fix segfault in MKSTR

Can't assume that the string resulting from an FFI call is not null!
The RTS generally assumes strings are not null later, however, so it's
important to test.
This commit is contained in:
Edwin Brady 2013-10-06 14:53:36 +01:00
parent 631fc46f75
commit 0d5c5b650b

View File

@ -146,12 +146,21 @@ VAL MKFLOAT(VM* vm, double val) {
}
VAL MKSTR(VM* vm, char* str) {
int len;
if (str == NULL) {
len = 0;
} else {
len = strlen(str)+1;
}
Closure* cl = allocate(vm, sizeof(Closure) + // Type) + sizeof(char*) +
sizeof(char)*strlen(str)+1, 0);
sizeof(char)*len, 0);
SETTY(cl, STRING);
cl -> info.str = (char*)cl + sizeof(Closure);
strcpy(cl -> info.str, str);
if (str == NULL) {
cl->info.str = NULL;
} else {
strcpy(cl -> info.str, str);
}
return cl;
}