From 287ab91739e5780834066f497db9b78755436912 Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Fri, 21 Oct 2016 23:18:18 -0700 Subject: [PATCH] VFS: Allow truncating memory chunk VFiles --- CHANGES | 1 + src/util/vfs/vfs-mem.c | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index 500d8736b..b23323b82 100644 --- a/CHANGES +++ b/CHANGES @@ -26,6 +26,7 @@ Misc: - GBA Video, GB Video: Colors are now fully scaled - PSP2: Improved controller rumble - GB, GBA: Prevent loading null ROMs + - VFS: Allow truncating memory chunk VFiles 0.5.1: (2016-10-05) Bugfixes: diff --git a/src/util/vfs/vfs-mem.c b/src/util/vfs/vfs-mem.c index d9a1a2520..174ef6587 100644 --- a/src/util/vfs/vfs-mem.c +++ b/src/util/vfs/vfs-mem.c @@ -116,7 +116,11 @@ void _vfmExpand(struct VFileMem* vfm, size_t newSize) { void* oldBuf = vfm->mem; vfm->mem = anonymousMemoryMap(newSize); if (oldBuf) { - memcpy(vfm->mem, oldBuf, vfm->size); + if (newSize < vfm->size) { + memcpy(vfm->mem, oldBuf, newSize); + } else { + memcpy(vfm->mem, oldBuf, vfm->size); + } mappedMemoryFree(oldBuf, vfm->size); } vfm->size = newSize; @@ -270,11 +274,7 @@ void _vfmUnmap(struct VFile* vf, void* memory, size_t size) { void _vfmTruncate(struct VFile* vf, size_t size) { struct VFileMem* vfm = (struct VFileMem*) vf; - if (size > vfm->size) { - _vfmExpand(vfm, size); - } else { - // TODO - } + _vfmExpand(vfm, size); } void _vfmTruncateNoop(struct VFile* vf, size_t size) {