diff options
author | Campbell Barton <ideasman42@gmail.com> | 2021-08-27 09:42:31 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2021-08-27 10:02:53 +0300 |
commit | 89dae554f9d5ae0204ad9c51c5ba00e14b16e858 (patch) | |
tree | 2dc6cc9151fe6eba664dfb5b39a14e7c620ce974 /source/blender/blenkernel/intern/text.c | |
parent | 523bc981cfeecead5050e7af44bbe252c166d718 (diff) |
Cleanup: utf8 stepping functions
Various changes to reduce risk of out of bounds errors in utf8 seeking.
- Remove BLI_str_prev_char_utf8
This function could potentially scan past the beginning of a string.
Use BLI_str_find_prev_char_utf8 instead which takes a limiting
string start argument.
- Swap arguments for BLI_str_find_prev_char_utf8 so the stepping
argument is first and the limiting argument is last.
This matches BLI_str_find_next_char_utf8.
- Change behavior of these functions to return it the start or end
pointers instead of NULL, which complicated use of these functions
to calculate offsets.
Callers that need to check if the limits were reached can compare
the return value with the start/end pointers.
- Return 'const char *' from these functions
so they don't remove const from the input arguments.
Diffstat (limited to 'source/blender/blenkernel/intern/text.c')
-rw-r--r-- | source/blender/blenkernel/intern/text.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c index 7f1f6590e48..bdc82fe626c 100644 --- a/source/blender/blenkernel/intern/text.c +++ b/source/blender/blenkernel/intern/text.c @@ -933,7 +933,7 @@ void txt_move_left(Text *text, const bool sel) (*charp) -= tabsize; } else { - const char *prev = BLI_str_prev_char_utf8((*linep)->line + *charp); + const char *prev = BLI_str_find_prev_char_utf8((*linep)->line + *charp, (*linep)->line); *charp = prev - (*linep)->line; } } @@ -1938,7 +1938,8 @@ void txt_backspace_char(Text *text) txt_pop_sel(text); } else { /* Just backspacing a char */ - const char *prev = BLI_str_prev_char_utf8(text->curl->line + text->curc); + const char *prev = BLI_str_find_prev_char_utf8(text->curl->line + text->curc, + text->curl->line); size_t c_len = prev - text->curl->line; c = BLI_str_utf8_as_unicode_step(text->curl->line, text->curl->len, &c_len); c_len -= prev - text->curl->line; |