fix(buf): use correct len fn on OOB check

This commit is contained in:
Cain 2024-09-07 00:53:21 +01:00
parent e39b880364
commit 786e9dad94

View file

@ -146,10 +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.
if self.cursor > self.remaining_length() {
if self.cursor > self.data_length() {
return Err(PacketUnderflow.context(format!(
"Cursor position {} is out of bounds when reading string. Buffer length: {}",
self.cursor, self.data.len()
self.cursor, self.data_length()
)));
}