#10 fix offbyone error in decode

This commit is contained in:
Erik Ekman 2007-02-08 20:32:17 +00:00
parent 7d7a81374e
commit 0e951ef007

View File

@ -170,28 +170,31 @@ decode_data(char *dest, int size, const char *src, char *srcend)
int padded; int padded;
char encoded[255]; char encoded[255];
char padding[5]; char padding[5];
int enclen;
char *pp; char *pp;
char *ep; char *ep;
memset(encoded, 0, sizeof(encoded)); memset(encoded, 0, sizeof(encoded));
memset(dest, 0, size); memset(dest, 0, size);
// The first char is not Base32-encoded, just pass it through /* First byte is not encoded */
*dest++ = *src++; *dest++ = *src++;
len = 1;
ep = encoded; ep = encoded;
while(src < srcend) { enclen = 0;
while(enclen < sizeof(encoded) && src < srcend) {
if(*src == '.') { if(*src == '.') {
src++; src++;
continue; continue;
} }
*ep++ = *src++; *ep++ = *src++;
enclen++;
} }
chunks = strlen(encoded) / 8; chunks = enclen / 8;
padded = strlen(encoded) % 8; padded = enclen % 8;
len = 0;
ep = encoded; ep = encoded;
for (i = 0; i < chunks-1; i++) { for (i = 0; i < chunks-1; i++) {
decode_chunk(dest, ep); decode_chunk(dest, ep);