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/editors/space_text | |
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/editors/space_text')
-rw-r--r-- | source/blender/editors/space_text/text_draw.c | 6 | ||||
-rw-r--r-- | source/blender/editors/space_text/text_ops.c | 2 |
2 files changed, 4 insertions, 4 deletions
diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c index b6ba95885e4..99fcb2092c3 100644 --- a/source/blender/editors/space_text/text_draw.c +++ b/source/blender/editors/space_text/text_draw.c @@ -1472,7 +1472,7 @@ static void draw_brackets(const SpaceText *st, const TextDrawContext *tdc, ARegi /* closing bracket, search backward for open */ fc--; if (c > 0) { - c -= linep->line + c - BLI_str_prev_char_utf8(linep->line + c); + c -= linep->line + c - BLI_str_find_prev_char_utf8(linep->line + c, linep->line); } while (linep) { while (fc >= 0) { @@ -1493,7 +1493,7 @@ static void draw_brackets(const SpaceText *st, const TextDrawContext *tdc, ARegi } fc--; if (c > 0) { - c -= linep->line + c - BLI_str_prev_char_utf8(linep->line + c); + c -= linep->line + c - BLI_str_find_prev_char_utf8(linep->line + c, linep->line); } } if (endl) { @@ -1508,7 +1508,7 @@ static void draw_brackets(const SpaceText *st, const TextDrawContext *tdc, ARegi fc = -1; } if (linep->len) { - c = BLI_str_prev_char_utf8(linep->line + linep->len) - linep->line; + c = BLI_str_find_prev_char_utf8(linep->line + linep->len, linep->line) - linep->line; } else { fc = -1; diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c index f480f60a2b9..b7185766224 100644 --- a/source/blender/editors/space_text/text_ops.c +++ b/source/blender/editors/space_text/text_ops.c @@ -1955,7 +1955,7 @@ static void txt_wrap_move_eol(SpaceText *st, ARegion *region, const bool sel) end = MIN2(end, i); if (chop) { - endj = BLI_str_prev_char_utf8((*linep)->line + j) - (*linep)->line; + endj = BLI_str_find_prev_char_utf8((*linep)->line + j, (*linep)->line) - (*linep)->line; } if (endj >= oldc) { |