diff --git a/src/fsLib.cpp b/src/fsLib.cpp index 2263d45..94a15ba 100644 --- a/src/fsLib.cpp +++ b/src/fsLib.cpp @@ -313,16 +313,16 @@ static int fsObjRead(lua_State *L) { } size_t dataBufLen = lineStrlen(dataBuf, FS_LINE_INCR); - if (dataBuf[dataBufLen - 1] == '\n' || dataBuf[dataBufLen - 1] == '\r') { - lua_pushlstring(L, dataBuf, dataBufLen - 1); - free(dataBuf); - return 1; - } else if (feof(data->fileStream)) { + if (feof(data->fileStream)) { data->eof = true; dataBufLen = ftell(data->fileStream); lua_pushlstring(L, dataBuf, dataBufLen - st); free(dataBuf); return 1; + } else if (dataBuf[dataBufLen - 1] == '\n' || dataBuf[dataBufLen - 1] == '\r') { + lua_pushlstring(L, dataBuf, dataBufLen - 1); + free(dataBuf); + return 1; } st = ftell(data->fileStream); @@ -341,16 +341,16 @@ static int fsObjRead(lua_State *L) { } size_t dataBufLen = lineStrlen(dataBuf, bufLen / sizeof(char)); - if (dataBuf[dataBufLen - 1] == '\n') { - lua_pushlstring(L, dataBuf, dataBufLen - 1); - free(dataBuf); - return 1; - } else if (feof(data->fileStream)) { + if (feof(data->fileStream)) { data->eof = true; dataBufLen = ftell(data->fileStream); lua_pushlstring(L, dataBuf, dataBufLen - st); free(dataBuf); return 1; + } else if (dataBuf[dataBufLen - 1] == '\n') { + lua_pushlstring(L, dataBuf, dataBufLen - 1); + free(dataBuf); + return 1; } } @@ -399,16 +399,16 @@ static int fsObjRead(lua_State *L) { } size_t dataBufLen = lineStrlen(dataBuf, FS_LINE_INCR); - if (dataBuf[dataBufLen - 1] == '\n' || dataBuf[dataBufLen - 1] == '\r') { - lua_pushlstring(L, dataBuf, dataBufLen - 1); - free(dataBuf); - return 1; - } else if (feof(data->fileStream)) { + if (feof(data->fileStream)) { data->eof = true; dataBufLen = ftell(data->fileStream); lua_pushlstring(L, dataBuf, dataBufLen - st); free(dataBuf); return 1; + } else if (dataBuf[dataBufLen - 1] == '\n' || dataBuf[dataBufLen - 1] == '\r') { + lua_pushlstring(L, dataBuf, dataBufLen - 1); + free(dataBuf); + return 1; } st = ftell(data->fileStream); @@ -427,16 +427,16 @@ static int fsObjRead(lua_State *L) { } size_t dataBufLen = lineStrlen(dataBuf, bufLen / sizeof(char)); - if (dataBuf[dataBufLen - 1] == '\n' || dataBuf[dataBufLen - 1] == '\r') { - lua_pushlstring(L, dataBuf, dataBufLen - 1); - free(dataBuf); - return 1; - } else if (feof(data->fileStream)) { + if (feof(data->fileStream)) { data->eof = true; dataBufLen = ftell(data->fileStream); lua_pushlstring(L, dataBuf, dataBufLen - st); free(dataBuf); return 1; + } else if (dataBuf[dataBufLen - 1] == '\n' || dataBuf[dataBufLen - 1] == '\r') { + lua_pushlstring(L, dataBuf, dataBufLen - 1); + free(dataBuf); + return 1; } } } else { @@ -593,7 +593,7 @@ LUALIB_API int luaopen_fs(lua_State *L) { SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Unable to initialize cwd"); return 2; } - + free(fpath); luaL_newmetatable(L, "Riko4.fsObj");