Skip to content

Commit

Permalink
check dst bump while incrementing, remove needless bump at end (#9)
Browse files Browse the repository at this point in the history
* check dst bump while incrementing, remove needless bump at end

* fix
  • Loading branch information
charlesnicholson authored Apr 22, 2021
1 parent 39a130b commit 4515f44
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions cobs.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ cobs_ret_t cobs_encode(void const *dec,
while (dec_len--) {
cobs_byte_t const byte = *src;
if (byte) {
*dst++ = byte;
if (dst >= dst_max) { return COBS_RET_ERR_EXHAUSTED; }
*dst = byte;
if (++dst >= dst_max) { return COBS_RET_ERR_EXHAUSTED; }
++code;
}

Expand All @@ -89,8 +89,7 @@ cobs_ret_t cobs_encode(void const *dec,
code = 1;

if ((byte == 0) || dec_len) {
++dst;
if (dst >= dst_max) { return COBS_RET_ERR_EXHAUSTED; }
if (++dst >= dst_max) { return COBS_RET_ERR_EXHAUSTED; }
}
}
++src;
Expand Down

0 comments on commit 4515f44

Please sign in to comment.