Skip to content

Commit

Permalink
find: Fix check length
Browse files Browse the repository at this point in the history
  • Loading branch information
MaJerle committed Aug 22, 2023
1 parent 90ea272 commit 263d821
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lwrb/src/lwrb/lwrb.c
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ lwrb_advance(lwrb_t* buff, size_t len) {
*/
uint8_t
lwrb_find(const lwrb_t* buff, const void* bts, size_t len, size_t start_offset, size_t* found_idx) {
size_t full, r;
size_t full, r, max_x;
uint8_t found = 0;
const uint8_t* needle = bts;

Expand All @@ -566,7 +566,8 @@ lwrb_find(const lwrb_t* buff, const void* bts, size_t len, size_t start_offset,
}

/* Max number of for loops is buff_full - input_len - start_offset of buffer length */
for (size_t skip_x = start_offset; !found && skip_x < (full - start_offset - len); ++skip_x) {
max_x = full - len;
for (size_t skip_x = start_offset; !found && skip_x <= max_x; ++skip_x) {
found = 1; /* Found by default */

/* Prepare the starting point for reading */
Expand Down

0 comments on commit 263d821

Please sign in to comment.