From f04fe4e4a38bfdbefbc0832e4a3eab1f0d9d4dab Mon Sep 17 00:00:00 2001 From: Ryan McConnell Date: Sat, 3 Jan 2026 12:08:12 -0500 Subject: [PATCH] `memfiles.nim` resizeFile fallback logic bug (#25408) `e` is not cleared when falling back to `ftruncate` (cherry picked from commit 4b615aca46d1f2f0932e8a1a0319e449ff9e9468) --- lib/pure/memfiles.nim | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/pure/memfiles.nim b/lib/pure/memfiles.nim index 2ba26e5c84..8e2f61868e 100644 --- a/lib/pure/memfiles.nim +++ b/lib/pure/memfiles.nim @@ -57,8 +57,12 @@ proc setFileSize(fh: FileHandle, newFileSize = -1, oldSize = -1): OSErrorCode = when declared(posix_fallocate): while (e = posix_fallocate(fh, 0, newFileSize); e == EINTR): discard - if (e == EINVAL or e == EOPNOTSUPP) and ftruncate(fh, newFileSize) == -1: - result = osLastError() # fallback arguable; Most portable BUT allows SEGV + if e == EINVAL or e == EOPNOTSUPP or e == ENOSYS: + # fallback arguable; Most portable BUT allows SEGV + if ftruncate(fh, newFileSize) == -1: + result = osLastError() + else: + discard elif e != 0: result = osLastError() else: # shrink the file