From 3649041195bac6494bdcd269872a06a11184df79 Mon Sep 17 00:00:00 2001 From: John Reiser Date: Mon, 19 Dec 2022 13:37:24 -0800 Subject: [PATCH] Return value of FileBase::seek(, SEEK_CUR) was not FileBase::tell() modified: file.cpp --- src/file.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/file.cpp b/src/file.cpp index 5cae7755..6e6c0d7f 100644 --- a/src/file.cpp +++ b/src/file.cpp @@ -117,6 +117,7 @@ void FileBase::closex() { throwIOException("close failed", errno); } +// Return value of ::seek is the resulting file offset (same as ::tell()) upx_off_t FileBase::seek(upx_off_t off, int whence) { if (!isOpen()) throwIOException("bad seek 1"); @@ -132,9 +133,11 @@ upx_off_t FileBase::seek(upx_off_t off, int whence) { off += _offset + _length; whence = SEEK_SET; } - if (::lseek(_fd, off, whence) < 0) + // SEEK_CUR falls through to here + upx_off_t rv = ::lseek(_fd, off, whence); + if (0 == (1+ rv)) // lazy coding to check for "-1" failure of ::lseek throwIOException("seek error", errno); - return off - _offset; + return rv - _offset; } upx_off_t FileBase::tell() const {