diff --git a/src/physfs.c b/src/physfs.c index 4c900a9b..8d2b9bbf 100644 --- a/src/physfs.c +++ b/src/physfs.c @@ -3199,7 +3199,12 @@ int PHYSFS_stat(const char *_fname, PHYSFS_Stat *stat) int __PHYSFS_readAll(PHYSFS_Io *io, void *buf, const size_t _len) { const PHYSFS_uint64 len = (PHYSFS_uint64) _len; - return (io->read(io, buf, len) == len); + PHYSFS_sint64 amount_read = io->read(io, buf, len); + if (amount_read < 0) + { + return 0; + } + return ((PHYSFS_uint64)amount_read == len); } /* __PHYSFS_readAll */ diff --git a/src/physfs_archiver_lec3d.c b/src/physfs_archiver_lec3d.c index 3d0c5012..764f3e2e 100644 --- a/src/physfs_archiver_lec3d.c +++ b/src/physfs_archiver_lec3d.c @@ -291,7 +291,7 @@ static int labLoadEntries(PHYSFS_Io *io, const PHYSFS_uint32 cnt, void *arc) PHYSFS_sint32 readlen; PHYSFS_sint64 savepos; char fn[32]; - int i; + PHYSFS_uint32 i; for (i = 0; i < cnt; i++) { diff --git a/src/physfs_archiver_zip.c b/src/physfs_archiver_zip.c index 7327a619..89698146 100644 --- a/src/physfs_archiver_zip.c +++ b/src/physfs_archiver_zip.c @@ -553,7 +553,7 @@ static PHYSFS_sint64 zip_find_end_of_central_dir(PHYSFS_Io *io, PHYSFS_sint64 *l * and call it a corrupted zipfile. */ - if (sizeof (buf) < filelen) + if (sizeof (buf) < (PHYSFS_uint64)filelen) { filepos = filelen - sizeof (buf); maxread = sizeof (buf); diff --git a/src/physfs_byteorder.c b/src/physfs_byteorder.c index b2d3a2cf..91662242 100644 --- a/src/physfs_byteorder.c +++ b/src/physfs_byteorder.c @@ -82,7 +82,12 @@ PHYSFS_sint64 PHYSFS_swapSBE64(PHYSFS_sint64 x) { return x; } static inline int readAll(PHYSFS_File *file, void *val, const size_t len) { - return (PHYSFS_readBytes(file, val, len) == len); + PHYSFS_sint64 amount_read = PHYSFS_readBytes(file, val, len); + if (amount_read < 0) + { + return 0; + } + return ((PHYSFS_uint64)amount_read == len); } /* readAll */ #define PHYSFS_BYTEORDER_READ(datatype, swaptype) \ @@ -108,9 +113,14 @@ PHYSFS_BYTEORDER_READ(sint64, SBE64) PHYSFS_BYTEORDER_READ(uint64, UBE64) -static inline int writeAll(PHYSFS_File *f, const void *val, const size_t len) +static inline int writeAll(PHYSFS_File *file, const void *val, const size_t len) { - return (PHYSFS_writeBytes(f, val, len) == len); + PHYSFS_sint64 amount_written = PHYSFS_writeBytes(file, val, len); + if (amount_written < 0) + { + return 0; + } + return ((PHYSFS_uint64)amount_written == len); } /* writeAll */ #define PHYSFS_BYTEORDER_WRITE(datatype, swaptype) \ diff --git a/src/physfs_platform_posix.c b/src/physfs_platform_posix.c index 7ba5e107..87ab5dae 100644 --- a/src/physfs_platform_posix.c +++ b/src/physfs_platform_posix.c @@ -244,7 +244,7 @@ PHYSFS_sint64 __PHYSFS_platformRead(void *opaque, void *buffer, } while ((rc == -1) && (errno == EINTR)); BAIL_IF(rc == -1, errcodeFromErrno(), -1); assert(rc >= 0); - assert(rc <= len); + assert((PHYSFS_uint64)rc <= len); return (PHYSFS_sint64) rc; } /* __PHYSFS_platformRead */ @@ -263,7 +263,7 @@ PHYSFS_sint64 __PHYSFS_platformWrite(void *opaque, const void *buffer, } while ((rc == -1) && (errno == EINTR)); BAIL_IF(rc == -1, errcodeFromErrno(), rc); assert(rc >= 0); - assert(rc <= len); + assert((PHYSFS_uint64)rc <= len); return (PHYSFS_sint64) rc; } /* __PHYSFS_platformWrite */ diff --git a/src/physfs_platform_unix.c b/src/physfs_platform_unix.c index f580fda6..b14a0f90 100644 --- a/src/physfs_platform_unix.c +++ b/src/physfs_platform_unix.c @@ -278,8 +278,8 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0) /* older kernels don't have /proc/self ... try PID version... */ const unsigned long long pid = (unsigned long long) getpid(); char path[64]; - const int rc = (int) snprintf(path,sizeof(path),"/proc/%llu/exe",pid); - if ( (rc > 0) && (rc < sizeof(path)) ) + const int rc = snprintf(path,sizeof(path),"/proc/%llu/exe",pid); + if ( (rc > 0) && (rc < (int)sizeof(path)) ) retval = readSymLink(path); } /* if */ } /* if */ diff --git a/test/test_physfs.c b/test/test_physfs.c index a196c5a0..d90baeb7 100644 --- a/test/test_physfs.c +++ b/test/test_physfs.c @@ -981,7 +981,7 @@ static int cmd_cat(char *args) for (i = 0; i < rc; i++) fputc((int) buffer[i], stdout); - if (rc < sizeof (buffer)) + if (rc < (PHYSFS_sint64)sizeof (buffer)) { printf("\n\n"); if (!PHYSFS_eof(f)) @@ -1257,7 +1257,12 @@ static int cmd_append(char *args) bw = strlen(WRITESTR); rc = PHYSFS_writeBytes(f, WRITESTR, bw); - if (rc != bw) + if (rc < 0) + { + printf("Writing failed. Reason: [%s].\n", + PHYSFS_getLastError()); + } + else if ((PHYSFS_uint64)rc != bw) { printf("Wrote (%d) of (%d) bytes. Reason: [%s].\n", (int) rc, (int) bw, PHYSFS_getLastError()); @@ -1305,7 +1310,12 @@ static int cmd_write(char *args) bw = strlen(WRITESTR); rc = PHYSFS_writeBytes(f, WRITESTR, bw); - if (rc != bw) + if (rc < 0) + { + printf("Writing failed. Reason: [%s].\n", + PHYSFS_getLastError()); + } + else if ((size_t)rc != bw) { printf("Wrote (%d) of (%d) bytes. Reason: [%s].\n", (int) rc, (int) bw, PHYSFS_getLastError());