Skip to content

Commit

Permalink
wrong str size when moving text to prepend. (#16)
Browse files Browse the repository at this point in the history
Co-authored-by: Stephen Mathieson <[email protected]>
  • Loading branch information
diasbruno and stephenmathieson authored Jul 21, 2023
1 parent b8537f7 commit 736ba3c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ buffer_prepend(buffer_t *self, char *str) {

// move
move:
memmove(self->data + len, self->data, len + 1);
memmove(self->data + len, self->data, prev + 1);
memcpy(self->data, str, len);

return 0;
Expand Down
11 changes: 11 additions & 0 deletions test.c
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,16 @@ test_buffer_compact() {
buffer_free(buf);
}

void
test_buffer_prepend_issue_15() {
buffer_t *file = buffer_new();
assert(0 == buffer_append(file, "layout.bk.html"));
assert(0 == buffer_prepend(file, "./example/"));
assert(strlen("./example/layout.bk.html") == buffer_length(file));
equal("./example/layout.bk.html", buffer_string(file));
buffer_free(file);
}

int
main(){
test_buffer_new();
Expand All @@ -248,6 +258,7 @@ main(){
test_buffer_clear();
test_buffer_trim();
test_buffer_compact();
test_buffer_prepend_issue_15();
printf("\n \e[32m\u2713 \e[90mok\e[0m\n\n");
return 0;
}

0 comments on commit 736ba3c

Please sign in to comment.