From 255bf8f1edc480b85d0aa7e499d7b027749717e0 Mon Sep 17 00:00:00 2001 From: John Tytgat Date: Thu, 6 May 2004 21:18:26 +0000 Subject: [PATCH] [project @ 2004-05-06 21:18:26 by joty] [ Again, the same commit of 2004-05-03 ] ro_gui_set_icon_string() : - anti-flicker test didn't work when string is longer than icon text buffer length. - make sure we have a NUL char terminated string when new icon text is longer than icon buffer. svn path=/import/netsurf/; revision=837 --- riscos/wimp.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/riscos/wimp.c b/riscos/wimp.c index da87cbd8a..baa9d1fa0 100644 --- a/riscos/wimp.c +++ b/riscos/wimp.c @@ -106,28 +106,34 @@ char *ro_gui_get_icon_string(wimp_w w, wimp_i i) { * \param text string (copied) */ void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text) { - wimp_caret caret; + wimp_caret caret; wimp_icon_state ic; int old_len, len; - + /* Get the icon data */ ic.w = w; ic.i = i; - if (xwimp_get_icon_state(&ic)) return; - + if (xwimp_get_icon_state(&ic)) + return; + /* Check that the existing text is not the same as the updated text to stop flicker */ - if (!strncmp(ic.icon.data.indirected_text.text, text, - (unsigned int)ic.icon.data.indirected_text.size)) return; - + if (ic.icon.data.indirected_text.size + && !strncmp(ic.icon.data.indirected_text.text, text, + (unsigned int)ic.icon.data.indirected_text.size - 1)) + return; + /* Copy the text across */ old_len = strlen(ic.icon.data.indirected_text.text); - strncpy(ic.icon.data.indirected_text.text, text, - (unsigned int)ic.icon.data.indirected_text.size); - + if (ic.icon.data.indirected_text.size) { + strncpy(ic.icon.data.indirected_text.text, text, + (unsigned int)ic.icon.data.indirected_text.size - 1); + ic.icon.data.indirected_text.text[ic.icon.data.indirected_text.size - 1] = '\0'; + } + /* Handle the caret being in the icon */ if (!xwimp_get_caret_position(&caret)) { @@ -137,7 +143,7 @@ void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text) { xwimp_set_caret_position(w, i, caret.pos.x, caret.pos.y, -1, caret.index); } } - + /* Redraw the icon */ ro_gui_redraw_icon(w, i);