From 4cae3b8f1b623115ab8a20e4720789bc71a8e72f Mon Sep 17 00:00:00 2001 From: Per Inge Mathisen Date: Tue, 3 Feb 2009 17:02:17 +0000 Subject: [PATCH] Improve handling of an error in NETsendfile reported in issue #215. Add TODO about rewriting this whole function and reference to ticket. git-svn-id: svn+ssh://svn.gna.org/svn/warzone/trunk@6580 4a71c877-e1ca-e34f-864e-861f7616d084 --- lib/netplay/netplay.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/netplay/netplay.c b/lib/netplay/netplay.c index 563d51127..0a51952dd 100644 --- a/lib/netplay/netplay.c +++ b/lib/netplay/netplay.c @@ -1129,7 +1129,8 @@ BOOL NETsetupTCPIP(const char *machine) // //////////////////////////////////////////////////////////////////////// // File Transfer programs. -// send file. it returns % of file sent. when 100 it's complete. call until it returns 100. +/** Send file. It returns % of file sent when 100 it's complete. Call until it returns 100. + * @TODO Needs to be rewritten. See issue #215. */ #define MAX_FILE_TRANSFER_PACKET 256 UBYTE NETsendFile(BOOL newFile, char *fileName, UDWORD player) { @@ -1147,7 +1148,7 @@ UBYTE NETsendFile(BOOL newFile, char *fileName, UDWORD player) debug(LOG_WZ, "Reading...[directory: %s] %s", PHYSFS_getRealDir(fileName), fileName); if (pFileHandle == NULL) { - debug(LOG_ERROR, "Failed"); + debug(LOG_ERROR, "Failed to open %s for reading: %s", fileName, PHYSFS_getLastError()); return 0; // failed } // get the file's size. @@ -1162,6 +1163,11 @@ UBYTE NETsendFile(BOOL newFile, char *fileName, UDWORD player) PHYSFS_seek(pFileHandle, 0); } // read some bytes. + if (!pFileHandle) + { + debug(LOG_ERROR, "No filehandle"); + return 0; // failed + } bytesRead = PHYSFS_read(pFileHandle, inBuff,1, MAX_FILE_TRANSFER_PACKET); if (player == 0)