Skip to content

Commit

Permalink
refactor: make cmt_buf_split implementation simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
mpolitzer committed Apr 17, 2024
1 parent 07a86a0 commit 676b5ba
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions sys-utils/libcmt/src/buf.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,13 +42,20 @@ int cmt_buf_split(const cmt_buf_t *me, size_t lhs_length, cmt_buf_t *lhs, cmt_bu
return -EINVAL;
}

// handle aliasing
cmt_buf_t tmp[1] = {*me};
lhs->begin = tmp->begin;
lhs->end = rhs->begin = tmp->begin + lhs_length;
rhs->end = tmp->end;
uint8_t *begin = me->begin;
uint8_t *split = me->begin + lhs_length;
uint8_t *end = me->end;

return lhs->end > tmp->end ? -ENOBUFS : 0;
if (split < begin || end < split) {
return -ENOBUFS;
}

lhs->begin = begin;
lhs->end = split;
rhs->begin = split;
rhs->end = end;

return 0;
}

static int comma(const uint8_t *s, const uint8_t *end) {
Expand Down

0 comments on commit 676b5ba

Please sign in to comment.