Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/physfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */


Expand Down
2 changes: 1 addition & 1 deletion src/physfs_archiver_lec3d.c
Original file line number Diff line number Diff line change
Expand Up @@ -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++)
{
Expand Down
2 changes: 1 addition & 1 deletion src/physfs_archiver_zip.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
16 changes: 13 additions & 3 deletions src/physfs_byteorder.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand All @@ -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) \
Expand Down
4 changes: 2 additions & 2 deletions src/physfs_platform_posix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand All @@ -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 */

Expand Down
4 changes: 2 additions & 2 deletions src/physfs_platform_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
16 changes: 13 additions & 3 deletions test/test_physfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down Expand Up @@ -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());
Expand Down Expand Up @@ -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());
Expand Down