From e25efac5fb26c9bb07c8f918c69d9476af7bbdcc Mon Sep 17 00:00:00 2001 From: Vicki Pfau Date: Sun, 2 May 2021 22:35:28 -0700 Subject: [PATCH] Util: Fix loading UPS patches that affect the last byte of the file --- CHANGES | 1 + src/util/patch-ups.c | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 65ced1366..fe0225e4a 100644 --- a/CHANGES +++ b/CHANGES @@ -9,6 +9,7 @@ Other fixes: - Core: Fix memory leak in opening games from the library - Qt: Fix infrequent deadlock when using sync to video - Qt: Fix applying savetype-only overrides + - Util: Fix loading UPS patches that affect the last byte of the file Misc: - Qt: Rearrange menus some diff --git a/src/util/patch-ups.c b/src/util/patch-ups.c index ea1d531eb..6c0334feb 100644 --- a/src/util/patch-ups.c +++ b/src/util/patch-ups.c @@ -87,15 +87,16 @@ bool _UPSApplyPatch(struct Patch* patch, const void* in, size_t inSize, void* ou if (patch->vf->read(patch->vf, &byte, 1) != 1) { return false; } + if (!byte) { + break; + } if (offset >= outSize) { return false; } buf[offset] ^= byte; ++offset; - if (!byte) { - break; - } } + ++offset; alreadyRead = patch->vf->seek(patch->vf, 0, SEEK_CUR); }