aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2002-12-19 16:02:51 +0000
committerDaniel Stenberg <daniel@haxx.se>2002-12-19 16:02:51 +0000
commit1698015e3c9c28e9b7b9f4a68b2d628dc525fcf1 (patch)
tree350fe96e386091e9828e0545a537bd14fda0c1af
parent39dc14c0025fe942efcd4a7b903443fa0c9ae4a0 (diff)
Curl_base64_decode() fixed by Matthew B
-rw-r--r--lib/base64.c8
1 files changed, 6 insertions, 2 deletions
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;
}