Skip to content

Commit 1ee3a5a

Browse files
committed
Update buf_copy to also update length
1 parent 3672952 commit 1ee3a5a

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/buffer.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,14 +141,14 @@ GglError ggl_str_to_int64(GglBuffer str, int64_t value[static 1]) {
141141

142142
static GglError buf_write(void *ctx, GglBuffer buf) {
143143
GglBuffer *target = ctx;
144+
GglBuffer target_copy = *target;
144145

145-
GglError ret = ggl_buf_copy(buf, target);
146+
GglError ret = ggl_buf_copy(buf, &target_copy);
146147
if (ret != GGL_ERR_OK) {
147148
return ret;
148149
}
149150

150151
*target = ggl_buffer_substr(*target, buf.len, SIZE_MAX);
151-
152152
return GGL_ERR_OK;
153153
}
154154

@@ -159,13 +159,15 @@ GglWriter ggl_buf_writer(GglBuffer *buf) {
159159
GglError ggl_buf_copy(GglBuffer source, GglBuffer *target) {
160160
if (source.len == 0) {
161161
target->len = 0;
162-
GGL_LOGD("Source has zero length buffer");
162+
GGL_LOGT("Source has zero length buffer");
163163
return GGL_ERR_OK;
164164
}
165165
if (target->len < source.len) {
166166
GGL_LOGT("Failed to copy buffer due to insufficient space.");
167167
return GGL_ERR_NOMEM;
168168
}
169169
memcpy(target->data, source.data, source.len);
170+
target->len = source.len;
171+
170172
return GGL_ERR_OK;
171173
}

0 commit comments

Comments
 (0)