From a1d2ca50a8e6ae512c74ebc6fcc27887252f7814 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 30 Aug 2015 22:11:50 +0200 Subject: [PATCH] Fix #619 This fixes handling of status codes from PHYSFS functions and seems to solve crashes like in #619 --- src/common/resources/sdl_file_wrapper.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/common/resources/sdl_file_wrapper.cpp b/src/common/resources/sdl_file_wrapper.cpp index aec032df..2964550c 100644 --- a/src/common/resources/sdl_file_wrapper.cpp +++ b/src/common/resources/sdl_file_wrapper.cpp @@ -128,22 +128,22 @@ int CSDLFileWrapper::SDLSeek(SDL_RWops *context, int offset, int whence) default: case RW_SEEK_SET: { - int result = PHYSFS_seek(file, offset); - return result > 0 ? offset : -1; + auto result = PHYSFS_seek(file, offset); + return (result != 0) ? offset : -1; } case RW_SEEK_CUR: { int position = offset + PHYSFS_tell(file); - int result = PHYSFS_seek(file, position); - return result > 0 ? position : -1; + auto result = PHYSFS_seek(file, position); + return (result != 0) ? position : -1; } case RW_SEEK_END: { int position = PHYSFS_fileLength(file) - offset; - int result = PHYSFS_seek(file, position); - return result > 0 ? position : -1; + auto result = PHYSFS_seek(file, position); + return (result != 0) ? position : -1; } } } @@ -158,7 +158,8 @@ int CSDLFileWrapper::SDLRead(SDL_RWops *context, void *ptr, int size, int maxnum PHYSFS_File *file = static_cast(context->hidden.unknown.data1); SDL_memset(ptr, 0, size * maxnum); - return PHYSFS_read(file, ptr, size, maxnum); + auto result = PHYSFS_read(file, ptr, size, maxnum); + return (result >= 0) ? result : 0; } return 0;