From dd9d82295007c064462a9137974483bfd9c36de0 Mon Sep 17 00:00:00 2001 From: Project Nayuki Date: Sun, 27 Aug 2017 23:48:16 +0000 Subject: [PATCH] Fixed logic errors in Rust library code. --- rust/src/lib.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 1159c36..4c7de65 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -107,7 +107,9 @@ impl QrCode { } // Add terminator and pad up to a byte if applicable - let numzerobits = std::cmp::min(4, datacapacitybits - bb.len()) + (bb.len().wrapping_neg() & 7); + let numzerobits = std::cmp::min(4, datacapacitybits - bb.len()); + append_bits(&mut bb, 0, numzerobits as u8); + let numzerobits = bb.len().wrapping_neg() & 7; append_bits(&mut bb, 0, numzerobits as u8); // Pad with alternate bytes until data capacity is reached @@ -363,7 +365,7 @@ impl QrCode { let mut k: usize = 0; for i in 0 .. numblocks { let mut dat: Vec = Vec::with_capacity(shortblocklen + 1); - dat.copy_from_slice(&data[k .. k + shortblocklen - blockecclen + ((i < numshortblocks) as usize)]); + dat.extend_from_slice(&data[k .. k + shortblocklen - blockecclen + ((i >= numshortblocks) as usize)]); k += dat.len(); let ecc: Vec = rs.get_remainder(&dat); if i < numshortblocks {