From fcb64f8cb962a39e76a620f5ba7f2dad0c359ca4 Mon Sep 17 00:00:00 2001 From: Marc Schoolderman Date: Tue, 7 Jan 2025 13:34:41 +0100 Subject: [PATCH] rename 'i' --- src/pam/rpassword.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/pam/rpassword.rs b/src/pam/rpassword.rs index a1ac67ad2..3b97006c9 100644 --- a/src/pam/rpassword.rs +++ b/src/pam/rpassword.rs @@ -116,43 +116,43 @@ fn read_unbuffered_with_feedback( hide_input: &HiddenInput, ) -> io::Result { let mut password = PamBuffer::default(); - let mut i = 0; + let mut pw_len = 0; // invariant: the amount of nonzero-bytes in the buffer correspond - // with the amount of asterisks on the terminal (both tracked in `i`) + // with the amount of asterisks on the terminal (both tracked in `pw_len`) for read_byte in source.bytes() { let read_byte = read_byte?; if read_byte == b'\n' || read_byte == b'\r' { - erase_feedback(sink, i); + erase_feedback(sink, pw_len); let _ = sink.write(b"\n"); break; } if read_byte == hide_input.term_orig.c_cc[VEOF] { - erase_feedback(sink, i); + erase_feedback(sink, pw_len); password.fill(0); break; } if read_byte == hide_input.term_orig.c_cc[VERASE] { - if i > 0 { + if pw_len > 0 { erase_feedback(sink, 1); - password[i - 1] = 0; - i -= 1; + password[pw_len - 1] = 0; + pw_len -= 1; } } else if read_byte == hide_input.term_orig.c_cc[VKILL] { - erase_feedback(sink, i); + erase_feedback(sink, pw_len); password.fill(0); - i = 0; + pw_len = 0; } else { #[allow(clippy::collapsible_else_if)] - if let Some(dest) = password.get_mut(i) { + if let Some(dest) = password.get_mut(pw_len) { *dest = read_byte; - i += 1; + pw_len += 1; let _ = sink.write(b"*"); } else { - erase_feedback(sink, i); + erase_feedback(sink, pw_len); return Err(Error::new( ErrorKind::OutOfMemory,