refactor(buf): clean up out of bounds err msg

This commit is contained in:
Cain 2024-09-07 00:33:53 +01:00
parent 73f39510fe
commit e39b880364

View file

@ -146,11 +146,10 @@ impl<'a, B: ByteOrder> Buffer<'a, B> {
/// Returns a `BufferError` if there is an error decoding the string.
pub fn read_string<D: StringDecoder>(&mut self, until: Option<D::Delimiter>) -> GDResult<String> {
// Check if the cursor is out of bounds.
let remaining = self.remaining_length();
if self.cursor > remaining {
if self.cursor > self.remaining_length() {
return Err(PacketUnderflow.context(format!(
"Cursor position {} is out of bounds when reading string. Remaining bytes: {remaining}",
self.cursor
"Cursor position {} is out of bounds when reading string. Buffer length: {}",
self.cursor, self.data.len()
)));
}