| ... | @@ -66,11 +66,11 @@ pub const Hash = struct { | ... | @@ -66,11 +66,11 @@ pub const Hash = struct { |
| 66 | | 66 | |
| 67 | pub fn toSlice(ph: *const Hash) []const u8 { | 67 | pub fn toSlice(ph: *const Hash) []const u8 { |
| 68 | var end: usize = ph.bytes.len; | 68 | var end: usize = ph.bytes.len; |
| 69 | while (true) { | 69 | while (end > 0) { |
| 70 | if (end == 0) return &.{}; | | |
| 71 | end -= 1; | 70 | end -= 1; |
| 72 | if (ph.bytes[end] != 0) return ph.bytes[0 .. end + 1]; | 71 | if (ph.bytes[end] != 0) return ph.bytes[0 .. end + 1]; |
| 73 | } | 72 | } |
| | 73 | return ph.bytes[0..0]; |
| 74 | } | 74 | } |
| 75 | | 75 | |
| 76 | pub fn eql(a: *const Hash, b: *const Hash) bool { | 76 | pub fn eql(a: *const Hash, b: *const Hash) bool { |
| ... | @@ -196,7 +196,7 @@ test Hash { | ... | @@ -196,7 +196,7 @@ test Hash { |
| 196 | try std.testing.expectEqualStrings("nasm-2.16.1-3-vrr-ygAAoADH9XG3tOdvPNuHen_d-XeHndOG-nNXmved", result.toSlice()); | 196 | try std.testing.expectEqualStrings("nasm-2.16.1-3-vrr-ygAAoADH9XG3tOdvPNuHen_d-XeHndOG-nNXmved", result.toSlice()); |
| 197 | } | 197 | } |
| 198 | | 198 | |
| 199 | test "EmptyHash" { | 199 | test "empty hash" { |
| 200 | const hash = Hash.fromSlice(""); | 200 | const hash = Hash.fromSlice(""); |
| 201 | try std.testing.expectEqualStrings("", hash.toSlice()); | 201 | try std.testing.expectEqualStrings("", hash.toSlice()); |
| 202 | } | 202 | } |