1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 19:57:35 +00:00

AK: Fix MemoryStream seek from end

The seek offset is still applied positively when seeking from the end;
see the Kernel's seek implementation.
This commit is contained in:
kleines Filmröllchen 2023-09-14 11:24:55 +02:00 committed by Andrew Kaster
parent 784ac6b9f2
commit 8bcf25561b
2 changed files with 98 additions and 2 deletions

View file

@ -81,10 +81,10 @@ ErrorOr<size_t> FixedMemoryStream::seek(i64 offset, SeekMode seek_mode)
m_offset += offset;
break;
case SeekMode::FromEndPosition:
if (offset > static_cast<i64>(m_bytes.size()))
if (-offset > static_cast<i64>(m_bytes.size()))
return Error::from_string_view_or_print_error_and_return_errno("Offset past the start of the stream memory"sv, EINVAL);
m_offset = m_bytes.size() - offset;
m_offset = m_bytes.size() + offset;
break;
}
return m_offset;