summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2011-06-01 01:09:53 +0200
committerGravatar Nikias Bassen2011-06-01 01:09:53 +0200
commitfde488d1b961f77f27a43cf8732b95ab65baf471 (patch)
treec0d6d602906ad4ea535cd9f7797c2ae8f2eaa563 /src
parentbfd8c56c016d97e6845664c7bb2e9b0c65d8cb95 (diff)
downloadlibplist-fde488d1b961f77f27a43cf8732b95ab65baf471.tar.gz
libplist-fde488d1b961f77f27a43cf8732b95ab65baf471.tar.bz2
Fix base64 encoding
Diffstat (limited to 'src')
-rw-r--r--src/base64.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/src/base64.c b/src/base64.c
index 2326168..65c6061 100644
--- a/src/base64.c
+++ b/src/base64.c
@@ -53,20 +53,18 @@ char *base64encode(const unsigned char *buf, size_t *size)
unsigned char input[3];
unsigned int output[4];
while (n < *size) {
- input[0] = buf[n++];
- input[1] = (n < *size) ? buf[n++] : 0;
- input[2] = (n < *size) ? buf[n++] : 0;
+ input[0] = buf[n];
+ input[1] = (n+1 < *size) ? buf[n+1] : 0;
+ input[2] = (n+2 < *size) ? buf[n+2] : 0;
output[0] = input[0] >> 2;
output[1] = ((input[0] & 3) << 4) + (input[1] >> 4);
output[2] = ((input[1] & 15) << 2) + (input[2] >> 6);
output[3] = input[2] & 63;
outbuf[m++] = base64_str[(int)output[0]];
outbuf[m++] = base64_str[(int)output[1]];
- outbuf[m++] = base64_str[(int)output[2]];
- outbuf[m++] = base64_str[(int)output[3]];
- }
- while ((m % 4) != 0) {
- outbuf[m++] = base64_pad;
+ outbuf[m++] = (n+1 < *size) ? base64_str[(int)output[2]] : base64_pad;
+ outbuf[m++] = (n+2 < *size) ? base64_str[(int)output[3]] : base64_pad;
+ n+=3;
}
outbuf[m] = 0; // 0-termination!
*size = m;