diff options
author | Mike Erwin <significant.bit@gmail.com> | 2016-10-15 02:56:50 +0300 |
---|---|---|
committer | Mike Erwin <significant.bit@gmail.com> | 2016-10-15 03:00:31 +0300 |
commit | 3f0c0ed87dc99a62989df86c57150986251abb5e (patch) | |
tree | 9cfdbb78b01d2b210841c1cd19f1df8658733c1f /source/blender/blenfont/intern/blf_font.c | |
parent | 9904d73d9a653a54d055f708bbd881417377f349 (diff) |
BLF: fix crash on text input fields
Some strings have known length, others are NULL terminated (len = INT_MAX in this case).
Now font drawing knows to treat INT_MAX special.
Diffstat (limited to 'source/blender/blenfont/intern/blf_font.c')
-rw-r--r-- | source/blender/blenfont/intern/blf_font.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 7d734653ffc..42717e65d9b 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -174,6 +174,21 @@ static void blf_font_ensure_ascii_table(FontBLF *font) } \ } (void)0 +static unsigned verts_needed(const FontBLF *font, const char *str, size_t len) +{ + unsigned length = (unsigned)((len == INT_MAX) ? strlen(str) : len); + return length * 40; + /* (5 shadow + 5 blur) * 4 verts per quad + * TODO: determine exact count of quads, somthing like this: */ +#if 0 + unsigned quad_ct = 1 + (unsigned)font->blur; + if (font->flags & BLF_SHADOW) + quad_ct += (unsigned)font->shadow; + + immBegin(GL_QUADS, length * quad_ct * 4); +#endif +} + static void blf_font_draw_ex( FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info, int pen_y) @@ -189,16 +204,7 @@ static void blf_font_draw_ex( blf_font_ensure_ascii_table(font); - immBeginAtMost(GL_QUADS, (unsigned)len * 40); - /* (5 shadow + 5 blur) * 4 verts per quad - * TODO: determine exact count of quads, somthing like this: */ -#if 0 - unsigned quad_ct = 1 + (unsigned)font->blur; - if (font->flags & BLF_SHADOW) - quad_ct += (unsigned)font->shadow; - - immBegin(GL_QUADS, (unsigned)len * quad_ct * 4); -#endif + immBeginAtMost(GL_QUADS, verts_needed(font, str, len)); while ((i < len) && str[i]) { BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table); @@ -244,7 +250,7 @@ static void blf_font_draw_ascii_ex( blf_font_ensure_ascii_table(font); - immBeginAtMost(GL_QUADS, (unsigned)len * 40); + immBeginAtMost(GL_QUADS, verts_needed(font, str, len)); while ((c = *(str++)) && len--) { BLI_assert(c < 128); @@ -284,7 +290,7 @@ int blf_font_draw_mono(FontBLF *font, const char *str, size_t len, int cwidth) blf_font_ensure_ascii_table(font); - immBeginAtMost(GL_QUADS, (unsigned)len * 40); + immBeginAtMost(GL_QUADS, verts_needed(font, str, len)); while ((i < len) && str[i]) { BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table); |