ywkaras commented on a change in pull request #8736:
URL: https://github.com/apache/trafficserver/pull/8736#discussion_r833555751
##########
File path: include/tscore/ink_base64.h
##########
@@ -42,5 +42,16 @@ bool ats_base64_encode(const unsigned char *inBuffer, size_t
inBufferSize, char
bool ats_base64_decode(const char *inBuffer, size_t inBufferSize, unsigned
char *outBuffer, size_t outBufSize, size_t *length);
// Little helper functions to calculate minimum required output buffer for
encoding/decoding.
-#define ATS_BASE64_ENCODE_DSTLEN(_length) ((_length * 8) / 6 + 4)
-#define ATS_BASE64_DECODE_DSTLEN(_length) (((_length + 3) / 4) * 3)
+// These sizes include one byte for null termination, because
ats_base64_encode and ats_base64_decode will always write a null
+// terminator.
+inline constexpr size_t
+ats_base64_encode_dstlen(size_t length)
+{
+ return ((length + 2) / 3) * 4 + 1;
+}
+
+inline constexpr size_t
+ats_base64_decode_dstlen(size_t length)
+{
+ return ((length + 3) / 4) * 3 + 1;
+}
Review comment:
Then why not?
```
inline size_t
ats_base64_decode_dstlen(char const *data, size_t length)
{
ink_assert(!(length % 4));
size_t adjust = 0;
if (length && ('=' == data[length - 1])) {
adjust = ('=' == data[length - 2])) ? 2 : 1;
}
return (((length / 4) * 3) - adjust + 1;
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]