fix display of menu strings containing '%'
authorkub <derkub@gmail.com>
Fri, 26 Mar 2021 21:45:04 +0000 (22:45 +0100)
committerkub <derkub@gmail.com>
Wed, 26 Jan 2022 19:39:48 +0000 (19:39 +0000)
menu.c

diff --git a/menu.c b/menu.c
index 6c6392a..50138f3 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -207,10 +207,10 @@ static void smalltext_out16(int x, int y, const char *texto, int color)
 \r
        if (maxw < 0)\r
                return;\r
-\r
-       strncpy(buffer, texto, sizeof(buffer));\r
        if (maxw > sizeof(buffer) - 1)\r
                maxw = sizeof(buffer) - 1;\r
+\r
+       strncpy(buffer, texto, maxw);\r
        buffer[maxw] = 0;\r
 \r
        smalltext_out16_(x, y, buffer, color);\r
@@ -601,7 +601,7 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void))
                                name = ent->generate_name(ent->id, &offs);\r
                }\r
                if (name != NULL) {\r
-                       text_out16(x, y, name);\r
+                       text_out16(x, y, "%s", name);\r
                        leftname_end = x + (strlen(name) + 1) * me_mfont_w;\r
                }\r
 \r
@@ -609,7 +609,7 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void))
                case MB_NONE:\r
                        break;\r
                case MB_OPT_ONOFF:\r
-                       text_out16(x + col2_offs, y, me_read_onoff(ent) ? "ON" : "OFF");\r
+                       text_out16(x + col2_offs, y, "%s", me_read_onoff(ent) ? "ON" : "OFF");\r
                        break;\r
                case MB_OPT_RANGE:\r
                        text_out16(x + col2_offs, y, "%i", *(int *)ent->var);\r
@@ -650,7 +650,7 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void))
        h = (g_menuscreen_h - h) / 2; // bottom area height\r
        if (menu_error_msg[0] != 0) {\r
                if (h >= me_mfont_h + 4)\r
-                       text_out16(5, g_menuscreen_h - me_mfont_h - 4, menu_error_msg);\r
+                       text_out16(5, g_menuscreen_h - me_mfont_h - 4, "%s", menu_error_msg);\r
                else\r
                        lprintf("menu msg doesn't fit!\n");\r
 \r
@@ -813,7 +813,7 @@ static void draw_menu_message(const char *msg, void (*draw_more)(void))
        menu_draw_begin(1, 0);\r
 \r
        for (p = msg; *p != 0 && y <= g_menuscreen_h - me_mfont_h; y += me_mfont_h) {\r
-               text_out16(x, y, p);\r
+               text_out16(x, y, "%s", p);\r
 \r
                for (; *p != 0 && *p != '\n'; p++)\r
                        ;\r
@@ -855,7 +855,7 @@ static void do_delete(const char *fpath, const char *fname)
        snprintf(tmp + len, sizeof(tmp) - len, "%s - cancel)", nm);\r
        len = strlen(tmp);\r
 \r
-       text_out16(mid - me_mfont_w * len / 2, 12 * me_mfont_h, tmp);\r
+       text_out16(mid - me_mfont_w * len / 2, 12 * me_mfont_h, "%s", tmp);\r
        menu_draw_end();\r
 \r
        while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MA2));\r
@@ -1425,13 +1425,13 @@ static void draw_key_config(const me_bind_action *opts, int opt_cnt, int player_
                snprintf(buff2, sizeof(buff2), "%s", in_get_key_name(-1, -PBTN_MOK));\r
                snprintf(buff, sizeof(buff), "%s - bind, %s - clear", buff2,\r
                                in_get_key_name(-1, -PBTN_MA2));\r
-               text_out16(x, g_menuscreen_h - 4 * me_mfont_h, buff);\r
+               text_out16(x, g_menuscreen_h - 4 * me_mfont_h, "%s", buff);\r
        }\r
        else\r
                text_out16(x, g_menuscreen_h - 4 * me_mfont_h, "Press a button to bind/unbind");\r
 \r
        if (dev_count > 1) {\r
-               text_out16(x, g_menuscreen_h - 3 * me_mfont_h, dev_name);\r
+               text_out16(x, g_menuscreen_h - 3 * me_mfont_h, "%s", dev_name);\r
                text_out16(x, g_menuscreen_h - 2 * me_mfont_h, "Press left/right for other devs");\r
        }\r
 \r