Revision 639 libsylph/recv.c

recv.c (revision 639)
45 45
	if (size == 0)
46 46
		return NULL;
47 47

  
48
	buf = g_malloc(size);
48
	buf = g_malloc(size + 1);
49 49

  
50 50
	do {
51 51
		gint read_count;
52 52

  
53 53
		read_count = sock_read(sock, buf + count, size - count);
54
		if (read_count < 0) {
54
		if (read_count <= 0) {
55 55
			g_free(buf);
56 56
			return NULL;
57 57
		}
58 58
		count += read_count;
59 59
	} while (count < size);
60 60

  
61
	buf[size] = '\0';
62

  
61 63
	return buf;
62 64
}
63 65

  

Also available in: Unified diff