chiark / gitweb /
parse_slice_hex: Fix to properly handle odd-length slices
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 31 Mar 2022 19:09:35 +0000 (20:09 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Thu, 31 Mar 2022 19:09:35 +0000 (20:09 +0100)
Previously it would accept some of them, and parse them in a weird
way.  I don't think this is actually important.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
src/utils.rs

index 310d0772e75e1858a2525d739dde20b5884a591d..cfaafb3705fa747d593ed6f1dd734d1703506c7d 100644 (file)
@@ -716,7 +716,7 @@ pub fn fmt_hex(f: &mut Formatter, buf: &[u8]) {
 #[must_use]
 pub fn parse_slice_hex(s: &str, buf: &mut [u8]) -> usize {
   let l = s.len();
-  if l % 1 != 0 { throw!() }
+  if l % 2 != 0 { throw!() }
   let l = l/2;
   if l > buf.len() { throw!() }