diff options
-rw-r--r-- | src/console.cpp | 8 | ||||
-rw-r--r-- | src/fileio.cpp | 18 | ||||
-rw-r--r-- | src/network/network_client.cpp | 5 | ||||
-rw-r--r-- | src/saveload.cpp | 2 |
4 files changed, 19 insertions, 14 deletions
diff --git a/src/console.cpp b/src/console.cpp index 00e471e12..c1bb05676 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -271,8 +271,12 @@ static void IConsoleWriteToLogFile(const char *string) { if (_iconsole_output_file != NULL) { /* if there is an console output file ... also print it there */ - fwrite(string, strlen(string), 1, _iconsole_output_file); - fwrite("\n", 1, 1, _iconsole_output_file); + if (fwrite(string, strlen(string), 1, _iconsole_output_file) != 1 || + fwrite("\n", 1, 1, _iconsole_output_file) != 1) { + fclose(_iconsole_output_file); + _iconsole_output_file = NULL; + IConsolePrintF(_icolour_def, "cannot write to log file"); + } } } diff --git a/src/fileio.cpp b/src/fileio.cpp index c6eb90ca9..184d773ec 100644 --- a/src/fileio.cpp +++ b/src/fileio.cpp @@ -91,8 +91,8 @@ void FioSeekToFile(uint8 slot, uint32 pos) byte FioReadByte() { if (_fio.buffer == _fio.buffer_end) { - _fio.pos += FIO_BUFFER_SIZE; - fread(_fio.buffer = _fio.buffer_start, 1, FIO_BUFFER_SIZE, _fio.cur_fh); + _fio.buffer = _fio.buffer_start; + _fio.pos += fread(_fio.buffer, 1, FIO_BUFFER_SIZE, _fio.cur_fh); } return *_fio.buffer++; } @@ -124,8 +124,7 @@ uint32 FioReadDword() void FioReadBlock(void *ptr, uint size) { FioSeekTo(FioGetPos(), SEEK_SET); - _fio.pos += size; - fread(ptr, 1, size, _fio.cur_fh); + _fio.pos += fread(ptr, 1, size, _fio.cur_fh); } static inline void FioCloseFile(int slot) @@ -430,7 +429,7 @@ char *BuildWithFullPath(const char *dir) /* Add absolute path */ if (s == NULL || dest != s) { - getcwd(dest, MAX_PATH); + if (getcwd(dest, MAX_PATH) == NULL) *dest = '\0'; AppendPathSeparator(dest, MAX_PATH); ttd_strlcat(dest, dir, MAX_PATH); } @@ -484,8 +483,7 @@ static bool TarListAddFile(const char *filename) memset(&empty[0], 0, sizeof(empty)); while (!feof(f)) { - fread(&th, 1, 512, f); - pos += 512; + pos += fread(&th, 1, 512, f); /* Check if we have the new tar-format (ustar) or the old one (a lot of zeros after 'link' field) */ if (strncmp(th.magic, "ustar", 5) != 0 && memcmp(&th.magic, &empty[0], 512 - offsetof(TarHeader, magic)) != 0) { @@ -629,7 +627,7 @@ void ChangeWorkingDirectory(const char *exe) char *s = strrchr(exe, PATHSEPCHAR); if (s != NULL) { *s = '\0'; - chdir(exe); + if (chdir(exe) != 0) DEBUG(misc, 0, "Directory with the binary does not exist?"); *s = PATHSEPCHAR; } #ifdef WITH_COCOA @@ -671,14 +669,14 @@ void DetermineBasePaths(const char *exe) #if defined(__MORPHOS__) || defined(__AMIGA__) _searchpaths[SP_WORKING_DIR] = NULL; #else - getcwd(tmp, MAX_PATH); + if (getcwd(tmp, MAX_PATH) == NULL) *tmp = '\0'; AppendPathSeparator(tmp, MAX_PATH); _searchpaths[SP_WORKING_DIR] = strdup(tmp); #endif /* Change the working directory to that one of the executable */ ChangeWorkingDirectory((char*)exe); - getcwd(tmp, MAX_PATH); + if (getcwd(tmp, MAX_PATH) == NULL) *tmp = '\0'; AppendPathSeparator(tmp, MAX_PATH); _searchpaths[SP_BINARY_DIR] = strdup(tmp); diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp index 3516baa9f..7a1492b11 100644 --- a/src/network/network_client.cpp +++ b/src/network/network_client.cpp @@ -595,7 +595,10 @@ DEF_CLIENT_RECEIVE_COMMAND(PACKET_SERVER_MAP) if (maptype == MAP_PACKET_NORMAL) { // We are still receiving data, put it to the file - fwrite(p->buffer + p->pos, 1, p->size - p->pos, file_pointer); + if (fwrite(p->buffer + p->pos, 1, p->size - p->pos, file_pointer) != p->size - p->pos) { + _switch_mode_errorstr = STR_NETWORK_ERR_SAVEGAMEERROR; + return NETWORK_RECV_STATUS_SAVEGAME; + } _network_join_kbytes = ftell(file_pointer) / 1024; InvalidateWindow(WC_NETWORK_STATUS_WINDOW, 0); diff --git a/src/saveload.cpp b/src/saveload.cpp index 8a4eba1a7..f6edcf578 100644 --- a/src/saveload.cpp +++ b/src/saveload.cpp @@ -1114,7 +1114,7 @@ static uint ReadNoComp() static void WriteNoComp(uint size) { - fwrite(_sl.buf, 1, size, _sl.fh); + if (fwrite(_sl.buf, 1, size, _sl.fh) != size) SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_WRITEABLE); } static bool InitNoComp() |