Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCampbell Barton <ideasman42@gmail.com>2021-08-27 09:42:31 +0300
committerCampbell Barton <ideasman42@gmail.com>2021-08-27 10:02:53 +0300
commit89dae554f9d5ae0204ad9c51c5ba00e14b16e858 (patch)
tree2dc6cc9151fe6eba664dfb5b39a14e7c620ce974 /source/blender/blenfont
parent523bc981cfeecead5050e7af44bbe252c166d718 (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/blenfont')
-rw-r--r--source/blender/blenfont/intern/blf_font.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index dbcd1d6016d..27478bd7f8e 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -673,23 +673,23 @@ size_t blf_font_width_to_rstrlen(
GlyphBLF *g, *g_prev;
int pen_x, width_new;
size_t i, i_prev, i_tmp;
- char *s, *s_prev;
+ const char *s, *s_prev;
GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
const int width_i = (int)width;
i = BLI_strnlen(str, str_len);
- s = BLI_str_find_prev_char_utf8(str, &str[i]);
- i = (size_t)((s != NULL) ? s - str : 0);
- s_prev = BLI_str_find_prev_char_utf8(str, s);
- i_prev = (size_t)((s_prev != NULL) ? s_prev - str : 0);
+ s = BLI_str_find_prev_char_utf8(&str[i], str);
+ i = (size_t)(s - str);
+ s_prev = BLI_str_find_prev_char_utf8(s, str);
+ i_prev = (size_t)(s_prev - str);
i_tmp = i;
g = blf_utf8_next_fast(font, gc, str, str_len, &i_tmp, &c);
for (width_new = pen_x = 0; (s != NULL);
i = i_prev, s = s_prev, c = c_prev, g = g_prev, g_prev = NULL, width_new = pen_x) {
- s_prev = BLI_str_find_prev_char_utf8(str, s);
- i_prev = (size_t)((s_prev != NULL) ? s_prev - str : 0);
+ s_prev = BLI_str_find_prev_char_utf8(s, str);
+ i_prev = (size_t)(s_prev - str);
if (s_prev != NULL) {
i_tmp = i_prev;