Skip to content

Commit

Permalink
🎨 Fix #258
Browse files Browse the repository at this point in the history
  • Loading branch information
fennecdjay committed Feb 27, 2023
1 parent 97920d7 commit 6ae331b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
7 changes: 6 additions & 1 deletion src/lib/string.c
Expand Up @@ -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);
}
Expand Down
12 changes: 7 additions & 5 deletions tests/plug/compile_file.c
Expand Up @@ -14,10 +14,12 @@
#include <string.h>
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;
}

1 comment on commit 6ae331b

@elfring
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The error detection and corresponding exception handling is still incomplete.

Please sign in to comment.