From 4c2ab63185aba09cb454c2ab91f3c2b6b6052e11 Mon Sep 17 00:00:00 2001 From: Jeong YunWon Date: Fri, 12 May 2023 06:52:11 +0900 Subject: [PATCH] Fix repr(bytearray) in debug --- vm/src/bytesinner.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/vm/src/bytesinner.rs b/vm/src/bytesinner.rs index 3afdadbb7..dee193481 100644 --- a/vm/src/bytesinner.rs +++ b/vm/src/bytesinner.rs @@ -253,11 +253,12 @@ impl PyBytesInner { } pub fn repr_with_name(&self, class_name: &str, vm: &VirtualMachine) -> PyResult { + const DECORATION_LEN: isize = 2 + 3; // 2 for (), 3 for b"" => bytearray(b"") let escape = crate::literal::escape::AsciiEscape::new_repr(&self.elements); let len = escape .layout() .len - .and_then(|len| (len as isize).checked_add(2 + class_name.len() as isize)) + .and_then(|len| (len as isize).checked_add(DECORATION_LEN + class_name.len() as isize)) .ok_or_else(|| Self::new_repr_overflow_error(vm))? as usize; let mut buf = String::with_capacity(len); buf.push_str(class_name);