From 732d940744c667d7aae82db0fd7947939a0048f8 Mon Sep 17 00:00:00 2001 From: John Mark Bell Date: Sat, 30 May 2009 00:26:04 +0000 Subject: Stop ro_gui_get_icon_string() returning a pointer to a location on the stack. Make explicit the semantics that strings returned from this call are transient and will be invalidated by subsequent calls. svn path=/trunk/netsurf/; revision=7645 --- riscos/wimp.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'riscos/wimp.c') diff --git a/riscos/wimp.c b/riscos/wimp.c index fa69dc845..71443afb4 100644 --- a/riscos/wimp.c +++ b/riscos/wimp.c @@ -220,12 +220,18 @@ void ro_gui_force_redraw_icon(wimp_w w, wimp_i i) * \param i icon handle * \return NUL terminated string in icon * + * If the icon contains direct text then the returned data will + * be invalidated by the next call to this function. Therefore, + * all client calls to this function must either copy the string or + * ensure that this function is not called again until they are + * finished with the string data returned. + * * \todo this doesn't do local encoding -> UTF-8 to match what is done in * ro_gui_set_icon_string. */ const char *ro_gui_get_icon_string(wimp_w w, wimp_i i) { - wimp_icon_state ic; + static wimp_icon_state ic; os_error *error; char *itext; @@ -238,12 +244,11 @@ const char *ro_gui_get_icon_string(wimp_w w, wimp_i i) warn_user("WimpError", error->errmess); return NULL; } - itext = (ic.icon.flags & wimp_ICON_INDIRECTED) ? - ic.icon.data.indirected_text.text - : - ic.icon.data.text; + itext = (ic.icon.flags & wimp_ICON_INDIRECTED) + ? ic.icon.data.indirected_text.text : ic.icon.data.text; /* Guarantee NUL termination. */ itext[ro_gui_strlen(itext)] = '\0'; + return itext; } -- cgit v1.2.3