Browse Source

Merge pull request #253 from iongchun/fix-bytes-cpy

fix infinite loop in bytes_cpy when size is zero
Luke-Jr 12 years ago
parent
commit
5eb3d4a295
1 changed files with 6 additions and 1 deletions
  1. 6 1
      util.h

+ 6 - 1
util.h

@@ -179,8 +179,13 @@ void bytes_cat(bytes_t *b, const bytes_t *cat)
 static inline
 static inline
 void bytes_cpy(bytes_t *dst, const bytes_t *src)
 void bytes_cpy(bytes_t *dst, const bytes_t *src)
 {
 {
-	dst->allocsz = src->allocsz;
 	dst->sz = src->sz;
 	dst->sz = src->sz;
+	if (!dst->sz) {
+		dst->allocsz = 0;
+		dst->buf = NULL;
+		return;
+	}
+	dst->allocsz = src->allocsz;
 	size_t half;
 	size_t half;
 	while (dst->sz <= (half = dst->allocsz / 2))
 	while (dst->sz <= (half = dst->allocsz / 2))
 		dst->allocsz = half;
 		dst->allocsz = half;