Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add r_strbuf_copy API #15186

Merged
merged 1 commit into from
Oct 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion libr/anal/op.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ R_API RAnalOp *r_anal_op_copy(RAnalOp *op) {
nop->src[2] = r_anal_value_copy (op->src[2]);
nop->dst = r_anal_value_copy (op->dst);
r_strbuf_init (&nop->esil);
r_strbuf_set (&nop->esil, r_strbuf_get (&op->esil));
r_strbuf_copy (&nop->esil, &op->esil);
return nop;
}

Expand Down
1 change: 1 addition & 0 deletions libr/include/r_util/r_strbuf.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ R_API int r_strbuf_length(RStrBuf *sb);
R_API void r_strbuf_free(RStrBuf *sb);
R_API void r_strbuf_fini(RStrBuf *sb);
R_API void r_strbuf_init(RStrBuf *sb);
R_API bool r_strbuf_copy(RStrBuf *dst, RStrBuf *src);
R_API bool r_strbuf_equals(RStrBuf *sa, RStrBuf *sb);
R_API bool r_strbuf_reserve(RStrBuf *sb, int len);

Expand Down
19 changes: 19 additions & 0 deletions libr/util/strbuf.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ R_API void r_strbuf_init(RStrBuf *sb) {
memset (sb, 0, sizeof (RStrBuf));
}

R_API bool r_strbuf_copy(RStrBuf *dst, RStrBuf *src) {
r_return_val_if_fail (dst && src, false);
if (src->ptr) {
char *p = malloc (src->ptrlen);
if (!p) {
return false;
}
memcpy (p, src->ptr, src->ptrlen);
free (dst->ptr);
dst->ptr = p;
dst->ptrlen = src->ptrlen;
} else {
R_FREE (dst->ptr);
memcpy (dst->buf, src->buf, sizeof (dst->buf));
}
dst->len = src->len;
return true;
}

R_API bool r_strbuf_reserve(RStrBuf *sb, int len) {
r_return_val_if_fail (sb && len > 0, false);

Expand Down