From 885121e25db2ec9a8191a406085d91790a133d20 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Sat, 28 Nov 2020 13:26:44 +0100 Subject: libbb: change decode_base32/64 API to return the end of _dst_, not _src_. function old new delta decode_base64 173 178 +5 read_base64 222 220 -2 decode_base32 186 182 -4 handle_incoming_and_exit 2263 2239 -24 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/3 up/down: 5/-30) Total: -25 bytes Signed-off-by: Denys Vlasenko --- libbb/uuencode.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'libbb') diff --git a/libbb/uuencode.c b/libbb/uuencode.c index 139c60bd5..6e63bfc6a 100644 --- a/libbb/uuencode.c +++ b/libbb/uuencode.c @@ -86,9 +86,9 @@ void FAST_FUNC bb_uuencode(char *p, const void *src, int length, const char *tbl * If points to '\0', then the source was fully decoded. * (*pp_dst): advanced past the last written byte. */ -const char* FAST_FUNC decode_base64(char **pp_dst, const char *src) +char* FAST_FUNC decode_base64(char *dst, const char **pp_src) { - char *dst = *pp_dst; + const char *src = pp_src ? *pp_src : dst; /* for httpd.c, support NULL 2nd param */ unsigned ch = 0; unsigned t; int i = 0; @@ -129,16 +129,17 @@ const char* FAST_FUNC decode_base64(char **pp_dst, const char *src) ch = 0; } } - *pp_dst = dst; /* i is zero here if full 4-char block was decoded */ - return src - i; /* -i rejects truncations: e.g. "MQ" and "MQ=" (correct encoding is "MQ==" -> "1") */ + if (pp_src) + *pp_src = src - i; /* -i rejects truncations: e.g. "MQ" and "MQ=" (correct encoding is "MQ==" -> "1") */ + return dst; } #if ENABLE_BASE32 -const char* FAST_FUNC decode_base32(char **pp_dst, const char *src) +char* FAST_FUNC decode_base32(char *dst, const char **pp_src) { - char *dst = *pp_dst; - int64_t ch = 0; + const char *src = *pp_src; + uint64_t ch = 0; unsigned t; int i = 0; @@ -169,9 +170,9 @@ const char* FAST_FUNC decode_base32(char **pp_dst, const char *src) *dst++ = (char) ch; } } - *pp_dst = dst; /* i is zero here if full 8-char block was decoded */ - return src - i; + *pp_src = src - i; + return dst; tail: { const char *s = src; @@ -192,8 +193,8 @@ const char* FAST_FUNC decode_base32(char **pp_dst, const char *src) *dst++ = (char) ch; dst -= (i+1) * 2 / 3; /* discard last 1, 2, 3 or 4 bytes */ } - *pp_dst = dst; - return src; + *pp_src = src; + return dst; } #endif @@ -249,13 +250,13 @@ void FAST_FUNC read_base64(FILE *src_stream, FILE *dst_stream, int flags) if (uu_style_end && strcmp(buf, "====") == 0) return; - out_tail = buf; + in_tail = buf; #if ENABLE_BASE32 if (base32) - in_tail = decode_base32(&out_tail, buf); + out_tail = decode_base32(buf, &in_tail); else #endif - in_tail = decode_base64(&out_tail, buf); + out_tail = decode_base64(buf, &in_tail); fwrite(buf, (out_tail - buf), 1, dst_stream); -- cgit v1.2.3