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 diff
1.1 --- a/src/base64/base64.c Sun Apr 24 19:37:56 2011 +0200 1.2 +++ b/src/base64/base64.c Sun Apr 24 20:13:47 2011 +0200 1.3 @@ -40,7 +40,8 @@ 1.4 enc[i++] = '+'; 1.5 enc[i++] = '/'; 1.6 1.7 - outbuf = g_malloc(((len + 3) * 8) / 6); 1.8 + outbuf = g_malloc(((len + 3) * 8) / 6 +1); 1.9 + memset(outbuf, 0, ((len + 3) * 8) / 6 +1); 1.10 q = outbuf; 1.11 1.12 i = 0; 1.13 @@ -78,7 +79,8 @@ 1.14 guchar *p = buf, *q; 1.15 guint in[4]; 1.16 /* gchar *out = g_malloc(((strlen(buf)+3) * 3) / 4 + 1); */ 1.17 - gchar *out = g_malloc((strlen(buf) + 3) + 1); 1.18 + gchar *out = g_malloc((strlen(buf) + 3) + 1 +1); 1.19 + memset(out, 0, (strlen(buf) + 3) + 1 +1); 1.20 1.21 q = out; 1.22 *size = 0; 1.23 @@ -125,5 +127,6 @@ 1.24 } 1.25 } 1.26 } 1.27 + out[*size] = '\0'; 1.28 return out; 1.29 }