mirror of
https://github.com/ilyakooo0/Idris-dev.git
synced 2024-09-22 06:29:37 +03:00
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:
parent
631fc46f75
commit
0d5c5b650b
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user