Skip to content

Commit

Permalink
add write error detection in node_compile()
Browse files Browse the repository at this point in the history
  • Loading branch information
devsaurus committed Aug 10, 2015
1 parent 4a69d24 commit d0e6ab3
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion app/modules/node.c
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,10 @@ static int node_compile( lua_State* L )
int result = luaU_dump(L, f, writer, &file_fd, stripping);
lua_unlock(L);

fs_flush(file_fd);
if (fs_flush(file_fd) < 0) { // result codes aren't propagated by flash_fs.h
// overwrite Lua error, like writer() does in case of a file io error
result = 1;
}
fs_close(file_fd);
file_fd = FS_OPEN_OK - 1;

Expand All @@ -392,6 +395,9 @@ static int node_compile( lua_State* L )
if (result == LUA_ERR_CC_NOTINTEGER) {
return luaL_error(L, "target lua_Number is integral but fractional value found");
}
if (result == 1) { // result status generated by writer() or fs_flush() fail
return luaL_error(L, "writing to file failed");
}

return 0;
}
Expand Down

0 comments on commit d0e6ab3

Please sign in to comment.