Remove NUL-temrination from cs_base64_{encode,decode} functions

Preserve for the corresponding `mg_*` variants for compatibility.
This commit is contained in:
Deomid "rojer" Ryabkov authored and Deomid Ryabkov committed 2021-06-12 01:54:51 +01:00
1 parent 4699e90e99
commit abced77c24
5 files changed
+20 -30

No files matched your search

+2 -12
View File
@@ -101,24 +101,18 @@ void cs_base64_finish(struct cs_base64_ctx *ctx) {
while (j % 4 != 0) { \
BASE64_OUT('='); \
} \
BASE64_FLUSH()
#define BASE64_OUT(ch) \
do { \
dst[j++] = (ch); \
} while (0)
#define BASE64_FLUSH() \
do { \
dst[j++] = '\0'; \
} while (0)
void cs_base64_encode(const unsigned char *src, int src_len, char *dst) {
void cs_base64_encode(const unsigned char *src, int src_len, char *dst, int *enc_len) {
BASE64_ENCODE_BODY;
if (enc_len != NULL) *enc_len = j;
}
#undef BASE64_OUT
#undef BASE64_FLUSH
#if CS_ENABLE_STDIO
#define BASE64_OUT(ch) \
@@ -127,14 +121,11 @@ void cs_base64_encode(const unsigned char *src, int src_len, char *dst) {
j++; \
} while (0)
#define BASE64_FLUSH()
void cs_fprint_base64(FILE *f, const unsigned char *src, int src_len) {
BASE64_ENCODE_BODY;
}
#undef BASE64_OUT
#undef BASE64_FLUSH
#endif /* CS_ENABLE_STDIO */
/* Convert one byte of encoded base64 input stream to 6-bit chunk */
@@ -193,7 +184,6 @@ int cs_base64_decode(const unsigned char *s, int len, char *dst, int *dec_len) {
if (d == 200) break;
*dst++ = c << 6 | d;
}
*dst = 0;
if (dec_len != NULL) *dec_len = (dst - orig_dst);
return orig_len - len;
}