BLI_string_cursor_utf8: assert the cursor isn't negative

This commit is contained in:
Campbell Barton
2023-09-22 14:51:53 +10:00
parent 7a4aa60d4e
commit 94a8dafab0

View File

@@ -111,6 +111,8 @@ static eStrCursorDelimType cursor_delim_type_utf8(const char *ch_utf8,
bool BLI_str_cursor_step_next_utf8(const char *str, const int str_maxlen, int *pos)
{
/* NOTE: Keep in sync with #BLI_str_cursor_step_next_utf32. */
BLI_assert(str_maxlen >= 0);
BLI_assert(*pos >= 0);
if (*pos >= str_maxlen) {
return false;
@@ -133,6 +135,8 @@ bool BLI_str_cursor_step_next_utf8(const char *str, const int str_maxlen, int *p
bool BLI_str_cursor_step_prev_utf8(const char *str, const int str_maxlen, int *pos)
{
/* NOTE: Keep in sync with #BLI_str_cursor_step_prev_utf32. */
BLI_assert(str_maxlen >= 0);
BLI_assert(*pos >= 0);
if ((*pos > 0) && (*pos <= str_maxlen)) {
const char *str_pos = str + *pos;
@@ -230,6 +234,7 @@ bool BLI_str_cursor_step_next_utf32(const char32_t *str, const int str_maxlen, i
{
/* NOTE: Keep in sync with #BLI_str_cursor_step_next_utf8. */
BLI_assert(str_maxlen >= 0);
BLI_assert(*pos >= 0);
if (*pos >= str_maxlen) {
return false;
@@ -245,6 +250,7 @@ bool BLI_str_cursor_step_prev_utf32(const char32_t *str, const int str_maxlen, i
{
/* NOTE: Keep in sync with #BLI_str_cursor_step_prev_utf8. */
BLI_assert(str_maxlen >= 0);
BLI_assert(*pos >= 0);
UNUSED_VARS_NDEBUG(str_maxlen);
if (*pos <= 0) {