on master help sign in
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.

commit0d5c5b650bd406411ad8da2f21f68d4a69f14a3e authorEdwin Brady <ecb10@st-andrews.ac.uk> dateSun 6 Oct 2013, 14:53 (13 years ago) parent631fc46
1 file changed+12−3
rts/idris_rts.c+12−3
rts/idris_rts.c+12−3
@@ -146,12 +146,21 @@ VAL MKFLOAT(VM* vm, double val) {
146146}
147147
148148VAL MKSTR(VM* vm, char* str) {
149+ int len;
150+ if (str == NULL) {
151+ len = 0;
152+ } else {
153+ len = strlen(str)+1;
154+ }
149155 Closure* cl = allocate(vm, sizeof(Closure) + // Type) + sizeof(char*) +
150− sizeof(char)*strlen(str)+1, 0);
156+ sizeof(char)*len, 0);
151157 SETTY(cl, STRING);
152158 cl -> info.str = (char*)cl + sizeof(Closure);
153−
154− strcpy(cl -> info.str, str);
159+ if (str == NULL) {
160+ cl->info.str = NULL;
161+ } else {
162+ strcpy(cl -> info.str, str);
163+ }
155164 return cl;
156165}
157166