Author: tridge
Date: 2005-08-27 01:42:20 +0000 (Sat, 27 Aug 2005)
New Revision: 9671

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=9671

Log:
patch from Kai Blin fixing a bug in our base64 encoder

Modified:
   branches/SAMBA_4_0/source/lib/ldb/common/ldb_ldif.c


Changeset:
Modified: branches/SAMBA_4_0/source/lib/ldb/common/ldb_ldif.c
===================================================================
--- branches/SAMBA_4_0/source/lib/ldb/common/ldb_ldif.c 2005-08-27 00:30:11 UTC 
(rev 9670)
+++ branches/SAMBA_4_0/source/lib/ldb/common/ldb_ldif.c 2005-08-27 01:42:20 UTC 
(rev 9671)
@@ -155,10 +155,10 @@
        const char *b64 = 
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
        int bit_offset, byte_offset, idx, i;
        const uint8_t *d = (const uint8_t *)buf;
-       int bytes = (len*8 + 5)/6;
+       int bytes = (len*8 + 5)/6, pad_bytes = (bytes % 4) ? 4 - (bytes % 4) : 
0;
        char *out;
 
-       out = talloc_array(mem_ctx, char, bytes+2);
+       out = talloc_array(mem_ctx, char, bytes+pad_bytes+1);
        if (!out) return NULL;
 
        for (i=0;i<bytes;i++) {
@@ -175,7 +175,8 @@
                out[i] = b64[idx];
        }
 
-       out[i++] = '=';
+       for (;i<bytes+pad_bytes;i++)
+               out[i] = '=';
        out[i] = 0;
 
        return out;

Reply via email to