gui: Constify list title text

Use const char* pointers for list titles. Only one debug menu
actually modifies the title, and in that case it's legal to
cast away const because the title points to a known mutable
buffer on the stack.

Change-Id: Idb8ab307b9a6ec23a93d8420c5e19fafd9f59c30
This commit is contained in:
Aidan MacDonald 2022-09-18 20:07:12 +01:00
parent 420fb1163c
commit 5b0506e9de
8 changed files with 13 additions and 12 deletions

View file

@ -1247,7 +1247,8 @@ static int disk_callback(int btn, struct gui_synclist *lists)
int *cardnum = (int*)lists->data;
unsigned char card_name[6];
unsigned char pbuf[32];
char *title = lists->title;
/* Casting away const is safe; the buffer is defined as non-const. */
char *title = (char *)lists->title;
static const unsigned char i_vmin[] = { 0, 1, 5, 10, 25, 35, 60, 100 };
static const unsigned char i_vmax[] = { 1, 5, 10, 25, 35, 45, 80, 200 };
static const unsigned char * const kbit_units[] = { "kBit/s", "MBit/s", "GBit/s" };

View file

@ -103,7 +103,7 @@ static void _default_listdraw_fn(struct list_putlineinfo_t *list_info)
bool show_cursor = list_info->show_cursor;
bool have_icons = list_info->have_icons;
struct line_desc *linedes = list_info->linedes;
char *dsp_text = list_info->dsp_text;
const char *dsp_text = list_info->dsp_text;
if (is_title)
{

View file

@ -490,7 +490,7 @@ void gui_list_screen_scroll_out_of_view(bool enable)
* both the title and icon. Use NOICON if there is no icon.
*/
void gui_synclist_set_title(struct gui_synclist * gui_list,
char * title, enum themable_icons icon)
const char * title, enum themable_icons icon)
{
gui_list->title = title;
gui_list->title_icon = icon;

View file

@ -96,7 +96,7 @@ struct list_putlineinfo_t {
struct viewport *vp;
struct line_desc *linedes;
struct gui_synclist * list;
char *dsp_text;
const char *dsp_text;
bool is_selected;
bool is_title;
@ -185,7 +185,7 @@ struct gui_synclist
/* The data that will be passed to the callback function YOU implement */
void * data;
/* The optional title, set to NULL for none */
char * title;
const char * title;
/* Optional title icon */
enum themable_icons title_icon;
@ -233,7 +233,7 @@ extern void gui_synclist_select_item(struct gui_synclist * lists,
extern void gui_synclist_add_item(struct gui_synclist * lists);
extern void gui_synclist_del_item(struct gui_synclist * lists);
extern void gui_synclist_limit_scroll(struct gui_synclist * lists, bool scroll);
extern void gui_synclist_set_title(struct gui_synclist * lists, char * title,
extern void gui_synclist_set_title(struct gui_synclist * lists, const char * title,
enum themable_icons icon);
extern void gui_synclist_hide_selection_marker(struct gui_synclist *lists,
bool hide);
@ -301,7 +301,7 @@ extern bool list_do_action(int context, int timeout,
**/
struct simplelist_info {
char *title; /* title to show on the list */
const char *title; /* title to show on the list */
int count; /* number of items in the list, each item is selection_size high */
int selection_size; /* list selection size, usually 1 */
bool hide_selection;

View file

@ -49,11 +49,11 @@
static int update_delay = DEFAULT_UPDATE_DELAY;
static bool sbs_has_title[NB_SCREENS];
static char* sbs_title[NB_SCREENS];
static const char* sbs_title[NB_SCREENS];
static enum themable_icons sbs_icon[NB_SCREENS];
static bool sbs_loaded[NB_SCREENS] = { false };
bool sb_set_title_text(char* title, enum themable_icons icon, enum screen_type screen)
bool sb_set_title_text(const char* title, enum themable_icons icon, enum screen_type screen)
{
sbs_title[screen] = title;
/* Icon_NOICON == -1 which the skin engine wants at position 1, so + 2 */

View file

@ -39,7 +39,7 @@ struct viewport *sb_skin_get_info_vp(enum screen_type screen);
void sb_skin_update(enum screen_type screen, bool force);
void sb_skin_set_update_delay(int delay);
bool sb_set_title_text(char* title, enum themable_icons icon, enum screen_type screen);
bool sb_set_title_text(const char* title, enum themable_icons icon, enum screen_type screen);
void sb_skin_has_title(enum screen_type screen);
const char* sb_get_title(enum screen_type screen);
enum themable_icons sb_get_icon(enum screen_type screen);

View file

@ -387,7 +387,7 @@ struct plugin_api {
void (*gui_synclist_limit_scroll)(struct gui_synclist * lists, bool scroll);
bool (*gui_synclist_do_button)(struct gui_synclist * lists,
int *action, enum list_wrap wrap);
void (*gui_synclist_set_title)(struct gui_synclist *lists, char* title,
void (*gui_synclist_set_title)(struct gui_synclist *lists, const char* title,
enum themable_icons icon);
enum yesno_res (*gui_syncyesno_run)(const struct text_message * main_message,
const struct text_message * yes_message,

View file

@ -234,7 +234,7 @@ static void printcell_listdraw_fn(struct list_putlineinfo_t *list_info)
bool show_cursor = list_info->show_cursor;
bool have_icons = list_info->have_icons;
struct line_desc *linedes = list_info->linedes;
char *dsp_text = list_info->dsp_text;
const char *dsp_text = list_info->dsp_text;
struct viewport *vp = list_info->vp;
int line = list_info->line;