authorgravatar for 40419155+marximimus@users.noreply.github.commarximimus <40419155+marximimus@users.noreply.github.com> 2025-11-07 08:16:34+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-11-07 08:16:34+01:00
log2e8f8afc832112ad03125a403f66d7d9058eeac8
tree2cebdf2a4618bd8f57ad575c062fe31fc931ce1a
parent40132af3ad8e3c3eb74be935393a4c45830c3861
signaturebadge-check Signed by PGP key B5690EEEBB952194

Base64DecoderWithIgnore.calcSizeUpperBound cannot return an error (#25834)

* std: Base64DecoderWithIgnore.calcSizeUpperBound cannot return an error * std: update doc comment of Base64DecoderWithIgnore.calcSizeUpperBound

1 files changed, 5 insertions(+), 5 deletions(-)

lib/std/base64.zig+5-5
...@@ -313,9 +313,9 @@ pub const Base64DecoderWithIgnore = struct {...@@ -313,9 +313,9 @@ pub const Base64DecoderWithIgnore = struct {
313 return result;313 return result;
314 }314 }
315315
316 /// Return the maximum possible decoded size for a given input length - The actual length may be less if the input includes padding.316 /// Return the maximum possible decoded size for a given input length - The actual length may be
317 /// `InvalidPadding` is returned if the input length is not valid.317 /// less if the input includes padding or ignored characters.
318 pub fn calcSizeUpperBound(decoder_with_ignore: *const Base64DecoderWithIgnore, source_len: usize) Error!usize {318 pub fn calcSizeUpperBound(decoder_with_ignore: *const Base64DecoderWithIgnore, source_len: usize) usize {
319 var result = source_len / 4 * 3;319 var result = source_len / 4 * 3;
320 if (decoder_with_ignore.decoder.pad_char == null) {320 if (decoder_with_ignore.decoder.pad_char == null) {
321 const leftover = source_len % 4;321 const leftover = source_len % 4;
...@@ -521,7 +521,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [...@@ -521,7 +521,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
521 {521 {
522 const decoder_ignore_nothing = codecs.decoderWithIgnore("");522 const decoder_ignore_nothing = codecs.decoderWithIgnore("");
523 var buffer: [0x100]u8 = undefined;523 var buffer: [0x100]u8 = undefined;
524 const decoded = buffer[0..try decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)];524 const decoded = buffer[0..decoder_ignore_nothing.calcSizeUpperBound(expected_encoded.len)];
525 const written = try decoder_ignore_nothing.decode(decoded, expected_encoded);525 const written = try decoder_ignore_nothing.decode(decoded, expected_encoded);
526 try testing.expect(written <= decoded.len);526 try testing.expect(written <= decoded.len);
527 try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);527 try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
...@@ -531,7 +531,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [...@@ -531,7 +531,7 @@ fn testAllApis(codecs: Codecs, expected_decoded: []const u8, expected_encoded: [
531fn testDecodeIgnoreSpace(codecs: Codecs, expected_decoded: []const u8, encoded: []const u8) !void {531fn testDecodeIgnoreSpace(codecs: Codecs, expected_decoded: []const u8, encoded: []const u8) !void {
532 const decoder_ignore_space = codecs.decoderWithIgnore(" ");532 const decoder_ignore_space = codecs.decoderWithIgnore(" ");
533 var buffer: [0x100]u8 = undefined;533 var buffer: [0x100]u8 = undefined;
534 const decoded = buffer[0..try decoder_ignore_space.calcSizeUpperBound(encoded.len)];534 const decoded = buffer[0..decoder_ignore_space.calcSizeUpperBound(encoded.len)];
535 const written = try decoder_ignore_space.decode(decoded, encoded);535 const written = try decoder_ignore_space.decode(decoded, encoded);
536 try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);536 try testing.expectEqualSlices(u8, expected_decoded, decoded[0..written]);
537}537}