Browse Source

fix infinite loop in bytes_cpy when size is zero

Ang Iongchun 12 years ago
parent
commit
162b65b6a0
1 changed files with 1 additions and 1 deletions
  1. 1 1
      util.h

+ 1 - 1
util.h

@@ -182,7 +182,7 @@ void bytes_cpy(bytes_t *dst, const bytes_t *src)
 	dst->allocsz = src->allocsz;
 	dst->allocsz = src->allocsz;
 	dst->sz = src->sz;
 	dst->sz = src->sz;
 	size_t half;
 	size_t half;
-	while (dst->sz <= (half = dst->allocsz / 2))
+	while (dst->allocsz > 0 && dst->sz <= (half = dst->allocsz / 2))
 		dst->allocsz = half;
 		dst->allocsz = half;
 	dst->buf = malloc(dst->allocsz);
 	dst->buf = malloc(dst->allocsz);
 	memcpy(dst->buf, src->buf, dst->sz);
 	memcpy(dst->buf, src->buf, dst->sz);