From 1698015e3c9c28e9b7b9f4a68b2d628dc525fcf1 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Thu, 19 Dec 2002 16:02:51 +0000 Subject: Curl_base64_decode() fixed by Matthew B --- lib/base64.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/base64.c b/lib/base64.c index 36393b893..f92f4f25e 100644 --- a/lib/base64.c +++ b/lib/base64.c @@ -61,6 +61,8 @@ static void decodeQuantum(unsigned char *dest, char *src) x = (x << 6) + 62; else if(src[i] == '/') x = (x << 6) + 63; + else if(src[i] == '=') + x = (x << 6); } dest[2] = (unsigned char)(x & 255); x >>= 8; @@ -78,6 +80,7 @@ static void base64Decode(unsigned char *dest, char *src, int *rawLength) int length = 0; int equalsTerm = 0; int i; + int numQuantums; unsigned char lastQuantum[3]; while((src[length] != '=') && src[length]) @@ -85,10 +88,11 @@ static void base64Decode(unsigned char *dest, char *src, int *rawLength) while(src[length+equalsTerm] == '=') equalsTerm++; + numQuantums = (length + equalsTerm) / 4; if(rawLength) - *rawLength = (length * 3 / 4) - equalsTerm; + *rawLength = (numQuantums * 3) - equalsTerm; - for(i = 0; i < length/4 - 1; i++) { + for(i = 0; i < numQuantums - 1; i++) { decodeQuantum(dest, src); dest += 3; src += 4; } -- cgit v1.2.3