diff options
author | Campbell Barton <campbell@blender.org> | 2022-09-30 07:56:01 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-09-30 08:03:18 +0300 |
commit | dbc097d6b8f8391832d8ffe051ca7ffaf37853fe (patch) | |
tree | 74061b3f95d2b5211bec2f84159e220f52ddcddd /source/blender | |
parent | 8bdd4b468554446cb1351785f0db751e2f84341f (diff) |
Fix error in blf_get_sample_text returning a pointer to stack memory
Copy-by-value was used when iterating over unicode_samples which
then referenced an array from the value.
Resolve by referencing a const pointer to the unicode_sample array.
Diffstat (limited to 'source/blender')
-rw-r--r-- | source/blender/blenfont/intern/blf_thumbs.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/source/blender/blenfont/intern/blf_thumbs.c b/source/blender/blenfont/intern/blf_thumbs.c index 2eed7418220..e4eed070e24 100644 --- a/source/blender/blenfont/intern/blf_thumbs.c +++ b/source/blender/blenfont/intern/blf_thumbs.c @@ -258,16 +258,18 @@ static const char32_t *blf_get_sample_text(FT_Face face) count_bits_i((uint)os2_table->ulUnicodeRange4); for (uint i = 0; i < ARRAY_SIZE(unicode_samples); ++i) { - UnicodeSample s = unicode_samples[i]; - if (os2_table && s.field && s.mask) { + const UnicodeSample *s = &unicode_samples[i]; + if (os2_table && s->field && s->mask) { /* OS/2 Table contains 4 contiguous integers of script coverage bit flags. */ - FT_ULong *field = &(os2_table->ulUnicodeRange1) + (s.field - 1); - if (!(*field & (FT_ULong)s.mask)) { + const FT_ULong *unicode_range = &os2_table->ulUnicodeRange1; + const size_t index = (s->field - 1); + BLI_assert(index < 4); + if (!(unicode_range[index] & (FT_ULong)s->mask)) { continue; } } - if (FT_Get_Char_Index(face, s.sample[0]) != 0) { - sample = s.sample; + if (FT_Get_Char_Index(face, s->sample[0]) != 0) { + sample = s->sample; break; } } |