From: Stephan Bosch Date: Wed, 4 Sep 2019 23:17:55 +0000 (+0200) Subject: lib: base64 - Restructure base64_encode_get_size(). X-Git-Tag: 2.3.8~97 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=dd3d49e439ab4cb5e5b50ee8d3c0000a34760ab8;p=thirdparty%2Fdovecot%2Fcore.git lib: base64 - Restructure base64_encode_get_size(). --- diff --git a/src/lib/base64.c b/src/lib/base64.c index a66446f4f0..c429c9052a 100644 --- a/src/lib/base64.c +++ b/src/lib/base64.c @@ -102,7 +102,6 @@ size_t base64_encode_get_size(struct base64_encoder *enc, size_t src_size) { bool crlf = HAS_ALL_BITS(enc->flags, BASE64_ENCODE_FLAG_CRLF); size_t out_size = base64_encode_get_out_size(enc, src_size); - size_t line_part, lines; if (src_size == 0) { /* last block */ @@ -120,16 +119,18 @@ size_t base64_encode_get_size(struct base64_encoder *enc, size_t src_size) } } - if (enc->max_line_len == SIZE_MAX) - return out_size; + if (enc->max_line_len < SIZE_MAX) { + size_t line_part, lines; - /* Calculate how many line endings must be added */ - lines = out_size / enc->max_line_len; - line_part = out_size % enc->max_line_len; - if (enc->cur_line_len > (enc->max_line_len - line_part)) - lines++; + /* Calculate how many line endings must be added */ + lines = out_size / enc->max_line_len; + line_part = out_size % enc->max_line_len; + if (enc->cur_line_len > (enc->max_line_len - line_part)) + lines++; + + out_size += lines * (crlf ? 2 : 1); + } - out_size += lines * (crlf ? 2 : 1); return out_size; }