telepathy-gabble: Make line-wrapped base64 allocation clearer
Will Thompson
wjt at kemper.freedesktop.org
Wed Nov 14 07:54:00 PST 2012
Module: telepathy-gabble
Branch: master
Commit: e27b7af0d486b80fe370bd9bcbe6e109dfe1aec9
URL: http://cgit.freedesktop.org/telepathy/telepathy-gabble/commit/?id=e27b7af0d486b80fe370bd9bcbe6e109dfe1aec9
Author: Will Thompson <will.thompson at collabora.co.uk>
Date: Wed Nov 14 15:32:42 2012 +0000
Make line-wrapped base64 allocation clearer
---
src/conn-avatars.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/src/conn-avatars.c b/src/conn-avatars.c
index 34ca5f8..b74af5d 100644
--- a/src/conn-avatars.c
+++ b/src/conn-avatars.c
@@ -838,9 +838,13 @@ gabble_connection_set_avatar (TpSvcConnectionInterfaceAvatars *iface,
if (avatar != NULL && avatar->len > 0)
{
gint state = 0, save = 0, outlen;
+ /* See the documentation for g_base64_encode_step(). */
+ guint base64_data_size = (avatar->len / 3 + 1) * 4 + 4;
+ guint base64_line_wrapped_data_size =
+ base64_data_size + (base64_data_size / 72) + 1;
ctx->avatar = g_string_new_len (avatar->data, avatar->len);
- base64 = g_malloc (((avatar->len / 3 + 1) *4 + 4) + ((avatar->len / 3 + 1) * 4 + 4) / 72 + 1);
+ base64 = g_malloc (base64_line_wrapped_data_size);
outlen = g_base64_encode_step ((const guchar *) avatar->data,
avatar->len, TRUE, base64, &state, &save);
outlen += g_base64_encode_close (TRUE, base64 + outlen, &state, &save);
More information about the telepathy-commits
mailing list