Mercurial > masqmail
diff src/base64/base64.c @ 312:c74adb7c4f50
null-terminated the decoded base64 strings
The returned size is still the same. I only alloced one byte more and
filled it with zero.
TODO: I'm not sure if the allocated size is exact. It's large enough
but maybe too large.
author | meillo@marmaro.de |
---|---|
date | Sun, 24 Apr 2011 20:13:47 +0200 |
parents | 589c365d90b1 |
children | 41958685480d |
line wrap: on
line diff
--- a/src/base64/base64.c Sun Apr 24 19:37:56 2011 +0200 +++ b/src/base64/base64.c Sun Apr 24 20:13:47 2011 +0200 @@ -40,7 +40,8 @@ enc[i++] = '+'; enc[i++] = '/'; - outbuf = g_malloc(((len + 3) * 8) / 6); + outbuf = g_malloc(((len + 3) * 8) / 6 +1); + memset(outbuf, 0, ((len + 3) * 8) / 6 +1); q = outbuf; i = 0; @@ -78,7 +79,8 @@ guchar *p = buf, *q; guint in[4]; /* gchar *out = g_malloc(((strlen(buf)+3) * 3) / 4 + 1); */ - gchar *out = g_malloc((strlen(buf) + 3) + 1); + gchar *out = g_malloc((strlen(buf) + 3) + 1 +1); + memset(out, 0, (strlen(buf) + 3) + 1 +1); q = out; *size = 0; @@ -125,5 +127,6 @@ } } } + out[*size] = '\0'; return out; }