|
@@ -179,10 +179,15 @@ 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->allocsz > 0 && dst->sz <= (half = dst->allocsz / 2))
|
|
|
|
|
|
|
+ while (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);
|