From: fennecdjay Date: Mon, 27 Feb 2023 08:54:37 +0000 (+0100) Subject: :art: Fix #258 X-Git-Tag: nightly~201 X-Git-Url: http://10.10.0.4:5575/?a=commitdiff_plain;h=6ae331b67872c221979481e4ac057764c3d7c748;p=gwion.git :art: Fix #258 --- diff --git a/src/lib/string.c b/src/lib/string.c index b61f5b11..86b0489e 100644 --- a/src/lib/string.c +++ b/src/lib/string.c @@ -381,8 +381,13 @@ static SFUN(string_load) { fseek(f, 0, SEEK_END); const size_t sz = ftell(f); char c[sz + 1]; + c[sz] = '\0'; rewind(f); - (void)fread(c, 1, sz, f); + const size_t ret = fread(c, 1, sz, f); + if(ret != sz) { + xfun_handle(shred, "StringLoadException"); + return; + } fclose(f); *(M_Object*)RETURN = new_string(shred->info->vm->gwion, c); } diff --git a/tests/plug/compile_file.c b/tests/plug/compile_file.c index 5a230959..e3d21c8b 100644 --- a/tests/plug/compile_file.c +++ b/tests/plug/compile_file.c @@ -14,10 +14,12 @@ #include GWION_IMPORT(compile_file) { DECL_OB(FILE *, file, = fopen("rm_me.gw", "w+")); - fprintf(file, "1;"); - rewind(file); - const m_bool ret = + if(fprintf(file, "1;") >= 0) { + rewind(file); + const m_bool ret = compile_file(gwi->gwion, __FILE__, file) ? GW_OK : GW_ERROR; - fclose(file); - return ret; + fclose(file); + return ret; + } + return GW_ERROR; }