From acc20c7e590aa2dca3c5182b0de53437dae8c478 Mon Sep 17 00:00:00 2001 From: marximimus <40419155+marximimus@users.noreply.github.com> Date: Thu, 6 Nov 2025 09:49:10 +0100 Subject: [PATCH 1/2] std: Base64DecoderWithIgnore.calcSizeUpperBound cannot return an error --- lib/std/base64.zig | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/std/base64.zig b/lib/std/base64.zig index 8c08fd6786df..a2458a3131ea 100644 --- a/lib/std/base64.zig +++ b/lib/std/base64.zig @@ -315,7 +315,7 @@ pub const Base64DecoderWithIgnore = struct { /// Return the maximum possible decoded size for a given input length - The actual length may be less if the input includes padding. /// `InvalidPadding` is returned if the input length is not valid. - pub fn calcSizeUpperBound(decoder_with_ignore: *const Base64DecoderWithIgnore, source_len: usize) Error!usize { + pub fn calcSizeUpperBound(decoder_with_ignore: *const Base64DecoderWithIgnore, source_len: usize) usize { var result = source_len / 4 * 3; if (decoder_with_ignore.decoder.pad_char == null) { const leftover = source_len % 4; @@ -521,7 +521,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [ { const decoder_ignore_nothing = codecs.decoderWithIgnore(""); var buffer: [0x100]u8 = undefined; - const decoded = buffer[0..try decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)]; + const decoded = buffer[0..decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)]; const written = try decoder_ignore_nothing.decode(decoded, expected_encoded); try testing.expect(written <= decoded.len); try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]); @@ -531,7 +531,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [ fn testDecodeIgnoreSpace(codecs: Codecs, expected_decoded: []const u8, encoded: []const u8) !void { const decoder_ignore_space = codecs.decoderWithIgnore(" "); var buffer: [0x100]u8 = undefined; - const decoded = buffer[0..try decoder_ignore_space.calcSizeUpperBound(encoded.len)]; + const decoded = buffer[0..decoder_ignore_space.calcSizeUpperBound(encoded.len)]; const written = try decoder_ignore_space.decode(decoded, encoded); try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]); } From 59e4725e08113b08b8abb9f9cc92ec3cf3cfafae Mon Sep 17 00:00:00 2001 From: marximimus <40419155+marximimus@users.noreply.github.com> Date: Thu, 6 Nov 2025 10:58:14 +0100 Subject: [PATCH 2/2] std: update doc comment of Base64DecoderWithIgnore.calcSizeUpperBound --- lib/std/base64.zig | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/std/base64.zig b/lib/std/base64.zig index a2458a3131ea..644ddd6a5bf5 100644 --- a/lib/std/base64.zig +++ b/lib/std/base64.zig @@ -313,8 +313,8 @@ pub const Base64DecoderWithIgnore = struct { return result; } - /// Return the maximum possible decoded size for a given input length - The actual length may be less if the input includes padding. - /// `InvalidPadding` is returned if the input length is not valid. + /// Return the maximum possible decoded size for a given input length - The actual length may be + /// less if the input includes padding or ignored characters. pub fn calcSizeUpperBound(decoder_with_ignore: *const Base64DecoderWithIgnore, source_len: usize) usize { var result = source_len / 4 * 3; if (decoder_with_ignore.decoder.pad_char == null) {