diff options
| author | Albrecht Schlosser <albrechts.fltk@online.de> | 2019-06-18 17:49:49 +0200 |
|---|---|---|
| committer | Albrecht Schlosser <albrechts.fltk@online.de> | 2019-06-18 17:49:49 +0200 |
| commit | fb3479aff259899eadc99a75de2474e3b9dbb0a9 (patch) | |
| tree | 9aa40aa79c3336504bc2c29f16bde9952de90c3b | |
| parent | 23484c30a9126dcda3f589cd63e3fe2ec8b41c98 (diff) | |
Avoid "uninitialized memory" error in gl_draw
As discussed in fltk.general, valgrind reported errors when gl_draw()
is called and the text is converted to a texture (i.e. when testing
whether the texture already exists).
We need a length check to make sure we don't overrun text buffers.
See threads "gl_draw" and "gl_draw - [General Use]", respectively,
started on Jun 19, 2019.
| -rw-r--r-- | src/gl_draw.cxx | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/gl_draw.cxx b/src/gl_draw.cxx index e45c870f3..5fe5822a8 100644 --- a/src/gl_draw.cxx +++ b/src/gl_draw.cxx @@ -263,6 +263,7 @@ private: char *utf8; //its text Fl_Font_Descriptor *fdesc; // its font float scale; // scaling factor of the GUI + int str_len; // the length of the utf8 text } data; data *fifo; // array of pile elements int size_; // pile height @@ -300,9 +301,11 @@ int gl_texture_fifo::already_known(const char *str, int n) { int rank; for ( rank = 0; rank <= last; rank++) { - if ( (memcmp(str, fifo[rank].utf8, n) == 0) && (fifo[rank].utf8[n] == 0) && - (fifo[rank].fdesc == gl_fontsize) && (fifo[rank].scale == gl_scale) ) { - return rank; + if ((fifo[rank].str_len == n) && + (fifo[rank].fdesc == gl_fontsize) && + (fifo[rank].scale == gl_scale) && + (memcmp(str, fifo[rank].utf8, n) == 0)) { + return rank; } } return -1; // means no texture exists yet for that string @@ -403,6 +406,7 @@ int gl_texture_fifo::compute_texture(const char* str, int n) fifo[current].utf8 = (char *)malloc(n + 1); memcpy(fifo[current].utf8, str, n); fifo[current].utf8[n] = 0; + fifo[current].str_len = n; // record length of text in utf8 fl_graphics_driver->font_descriptor(gl_fontsize); int w, h; w = fl_width(fifo[current].utf8, n) * gl_scale; |
