fix type usage for endianess in menu handling
authorkub <derkub@gmail.com>
Fri, 26 Mar 2021 18:57:58 +0000 (19:57 +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 e91f84a..65cb26a 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -494,24 +494,12 @@ static int me_count(const menu_entry *ent)
 \r
 static unsigned int me_read_onoff(const menu_entry *ent)\r
 {\r
-       // guess var size based on mask to avoid reading too much\r
-       if (ent->mask & 0xffff0000)\r
-               return *(unsigned int *)ent->var & ent->mask;\r
-       else if (ent->mask & 0xff00)\r
-               return *(unsigned short *)ent->var & ent->mask;\r
-       else\r
-               return *(unsigned char *)ent->var & ent->mask;\r
+       return *(unsigned int *)ent->var & ent->mask;\r
 }\r
 \r
 static void me_toggle_onoff(menu_entry *ent)\r
 {\r
-       // guess var size based on mask to avoid reading too much\r
-       if (ent->mask & 0xffff0000)\r
-               *(unsigned int *)ent->var ^= ent->mask;\r
-       else if (ent->mask & 0xff00)\r
-               *(unsigned short *)ent->var ^= ent->mask;\r
-       else\r
-               *(unsigned char *)ent->var ^= ent->mask;\r
+       *(unsigned int *)ent->var ^= ent->mask;\r
 }\r
 \r
 static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void))\r
@@ -645,7 +633,7 @@ static void me_draw(const menu_entry *entries, int sel, void (*draw_more)(void))
                                        offs += (10 - len - 2) * me_mfont_w;\r
                                if (offs < leftname_end)\r
                                        offs = leftname_end;\r
-                               if (i == *(unsigned char *)ent->var) {\r
+                               if (i == *(int *)ent->var) {\r
                                        text_out16(offs, y, "%s", names[i]);\r
                                        break;\r
                                }\r
@@ -710,11 +698,11 @@ static int me_process(menu_entry *entry, int is_next, int is_lr)
                        names = (const char **)entry->data;\r
                        for (c = 0; names[c] != NULL; c++)\r
                                ;\r
-                       *(signed char *)entry->var += is_next ? 1 : -1;\r
-                       if (*(signed char *)entry->var < 0)\r
-                               *(signed char *)entry->var = 0;\r
-                       if (*(signed char *)entry->var >= c)\r
-                               *(signed char *)entry->var = c - 1;\r
+                       *(int *)entry->var += is_next ? 1 : -1;\r
+                       if (*(int *)entry->var < 0)\r
+                               *(int *)entry->var = 0;\r
+                       if (*(int *)entry->var >= c)\r
+                               *(int *)entry->var = c - 1;\r
                        return 1;\r
                default:\r
                        return 0;\r