From 65f076de8f46234c26cd56f772ad85a6d4d3f24d Mon Sep 17 00:00:00 2001 From: LibretroAdmin Date: Sun, 14 Jun 2026 13:56:27 +0000 Subject: [PATCH] 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. --- src/file.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/file.c b/src/file.c index 3f6ba24..63a5e4d 100644 --- a/src/file.c +++ b/src/file.c @@ -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;