diff options
Diffstat (limited to 'libsylph/recv.c')
-rw-r--r-- | libsylph/recv.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/libsylph/recv.c b/libsylph/recv.c index 0b71545c..3d2a7968 100644 --- a/libsylph/recv.c +++ b/libsylph/recv.c @@ -45,19 +45,21 @@ gchar *recv_bytes(SockInfo *sock, glong size) if (size == 0) return NULL; - buf = g_malloc(size); + buf = g_malloc(size + 1); do { gint read_count; read_count = sock_read(sock, buf + count, size - count); - if (read_count < 0) { + if (read_count <= 0) { g_free(buf); return NULL; } count += read_count; } while (count < size); + buf[size] = '\0'; + return buf; } |