nostrdb

an unfairly fast embedded nostr database backed by lmdb
git clone git://jb55.com/nostrdb
Log | Files | Refs | Submodules | README | LICENSE

commit f023a210c8a45707a34834e0021dea1808c6b645
parent ef599917145cb0b94124b7c57e2ad39d6961074f
Author: William Casarin <jb55@jb55.com>
Date:   Sat, 23 Dec 2023 13:11:23 -0800

cursor: re-apply infinite loop bug fix

since I keep overwriting it by accident

Diffstat:
Msrc/cursor.h | 65++++++++++++++++++++++++++++++++---------------------------------
1 file changed, 32 insertions(+), 33 deletions(-)

diff --git a/src/cursor.h b/src/cursor.h @@ -614,39 +614,38 @@ static inline int is_alphanumeric(char c) { } static inline int consume_until_boundary(struct cursor *cur) { - unsigned int c; - unsigned int char_length = 1; - unsigned int *utf8_char_length = &char_length; - - while (cur->p < cur->end) { - c = *cur->p; - - *utf8_char_length = 1; - - if (is_whitespace(c)) - return 1; - - // Need to check for UTF-8 characters, which can be multiple bytes long - if (is_utf8_byte(c)) { - if (!parse_utf8_char(cur, &c, utf8_char_length)) { - if (!is_right_boundary(c)){ - // TODO: We should work towards handling all UTF-8 characters. - //printf("Invalid UTF-8 code point: %x\n", c); - } - } - } - - if (is_right_boundary(c)) - return 1; - - // Need to use a variable character byte length for UTF-8 (2-4 bytes) - if (cur->p + *utf8_char_length <= cur->end) - cur->p += *utf8_char_length; - else - cur->p++; - } - - return 1; + unsigned int c; + unsigned int char_length = 1; + unsigned int *utf8_char_length = &char_length; + + while (cur->p < cur->end) { + c = *cur->p; + + *utf8_char_length = 1; + + if (is_whitespace(c)) + return 1; + + // Need to check for UTF-8 characters, which can be multiple bytes long + if (is_utf8_byte(c)) { + if (!parse_utf8_char(cur, &c, utf8_char_length)) { + if (!is_right_boundary(c)){ + return 0; + } + } + } + + if (is_right_boundary(c)) + return 1; + + // Need to use a variable character byte length for UTF-8 (2-4 bytes) + if (cur->p + *utf8_char_length <= cur->end) + cur->p += *utf8_char_length; + else + cur->p++; + } + + return 1; } static inline int consume_until_whitespace(struct cursor *cur, int or_end) {