fceumm: fix -Wsign-compare in FCEU_fseek
offset is long while EMUFILE size/location are uint32_t, so the SEEK_SET and SEEK_CUR bounds checks mixed signed and unsigned operands. Cast to uint32_t for the comparisons, but first reject the cases a bare cast would silently wrap: a negative SEEK_SET offset, and a SEEK_CUR rewind past the start. Behaviour for valid seeks is unchanged; invalid negative seeks now fail cleanly instead of wrapping to a huge offset.
This commit is contained in:
committed by
U-DESKTOP-SPFP6AQ\twistedtechre
parent
e4b039b604
commit
65f076de8f
@@ -179,13 +179,15 @@ int FCEU_fseek(FCEUFILE *fp, long offset, int whence)
|
||||
switch (whence)
|
||||
{
|
||||
case SEEK_SET:
|
||||
if (offset >= fp->fp->size)
|
||||
if (offset < 0 || (uint32_t)offset >= fp->fp->size)
|
||||
return -1;
|
||||
|
||||
fp->fp->location = offset;
|
||||
fp->fp->location = (uint32_t)offset;
|
||||
break;
|
||||
case SEEK_CUR:
|
||||
if ((offset + fp->fp->location) > fp->fp->size)
|
||||
if (offset < 0 && (uint32_t)(-offset) > fp->fp->location)
|
||||
return -1;
|
||||
if ((uint32_t)(fp->fp->location + offset) > fp->fp->size)
|
||||
return -1;
|
||||
|
||||
fp->fp->location += offset;
|
||||
|
||||
Reference in New Issue
Block a user