From 8f73a9c255e5e6977e2b89ccf528a4988a23a540 Mon Sep 17 00:00:00 2001 From: En-En <39373446+En-En-Code@users.noreply.github.com> Date: Thu, 26 Sep 2024 20:52:04 -0500 Subject: [PATCH] Added range bound to keep internal cheat data within specified size The decision to change the value column to store G_TYPE_UINT is purely pragmatic--having all data be treated and displayed as unsized is simpler than writing a custom display to handle signedness and cleaner than 1-3 byte ints appearing unsigned and 4 byte int appearing signed. --- desmume/src/frontend/posix/gtk/cheatsGTK.cpp | 9 +++++++-- desmume/src/frontend/posix/gtk2/cheatsGTK.cpp | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/desmume/src/frontend/posix/gtk/cheatsGTK.cpp b/desmume/src/frontend/posix/gtk/cheatsGTK.cpp index 972926b58..a7c7af523 100644 --- a/desmume/src/frontend/posix/gtk/cheatsGTK.cpp +++ b/desmume/src/frontend/posix/gtk/cheatsGTK.cpp @@ -129,11 +129,15 @@ static void cheat_list_modify_cheat(GtkCellRendererText * cell, if (column == COLUMN_LO || column == COLUMN_HI || column == COLUMN_SIZE) { u32 v = 0; + u32 data; switch (column) { case COLUMN_SIZE: v = atoi(new_text); - cheats->update(v-1, cheat.code[0][0], cheat.code[0][1], + data = std::min(0xFFFFFFFF >> (24 - ((v-1) << 3)), + cheat.code[0][1]); + cheats->update(v-1, cheat.code[0][0], data, cheat.description, cheat.enabled, ii); + gtk_list_store_set(GTK_LIST_STORE(model), &iter, COLUMN_LO, data, -1); break; case COLUMN_HI: sscanf(new_text, "%x", &v); @@ -143,6 +147,7 @@ static void cheat_list_modify_cheat(GtkCellRendererText * cell, break; case COLUMN_LO: v = atoi(new_text); + v = std::min(0xFFFFFFFF >> (24 - (cheat.size << 3)), v); cheats->update(cheat.size, cheat.code[0][0], v, cheat.description, cheat.enabled, ii); break; @@ -303,7 +308,7 @@ static void cheatListEnd() static GtkListStore *cheat_list_populate() { GtkListStore *store = gtk_list_store_new (5, G_TYPE_BOOLEAN, - G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING); + G_TYPE_INT, G_TYPE_INT, G_TYPE_UINT, G_TYPE_STRING); CHEATS_LIST cheat; u32 chsize = cheats->getListSize(); diff --git a/desmume/src/frontend/posix/gtk2/cheatsGTK.cpp b/desmume/src/frontend/posix/gtk2/cheatsGTK.cpp index 093c563e7..845d0c509 100644 --- a/desmume/src/frontend/posix/gtk2/cheatsGTK.cpp +++ b/desmume/src/frontend/posix/gtk2/cheatsGTK.cpp @@ -129,11 +129,15 @@ static void cheat_list_modify_cheat(GtkCellRendererText * cell, if (column == COLUMN_LO || column == COLUMN_HI || column == COLUMN_SIZE) { u32 v = 0; + u32 data; switch (column) { case COLUMN_SIZE: v = atoi(new_text); - cheats->update(v-1, cheat.code[0][0], cheat.code[0][1], + data = std::min(0xFFFFFFFF >> (24 - ((v-1) << 3)), + cheat.code[0][1]); + cheats->update(v-1, cheat.code[0][0], data, cheat.description, cheat.enabled, ii); + gtk_list_store_set(GTK_LIST_STORE(model), &iter, COLUMN_LO, data, -1); break; case COLUMN_HI: sscanf(new_text, "%x", &v); @@ -143,6 +147,7 @@ static void cheat_list_modify_cheat(GtkCellRendererText * cell, break; case COLUMN_LO: v = atoi(new_text); + v = std::min(0xFFFFFFFF >> (24 - (cheat.size << 3)), v); cheats->update(cheat.size, cheat.code[0][0], v, cheat.description, cheat.enabled, ii); break; @@ -303,7 +308,7 @@ static void cheatListEnd() static GtkListStore *cheat_list_populate() { GtkListStore *store = gtk_list_store_new (5, G_TYPE_BOOLEAN, - G_TYPE_INT, G_TYPE_INT, G_TYPE_INT, G_TYPE_STRING); + G_TYPE_INT, G_TYPE_INT, G_TYPE_UINT, G_TYPE_STRING); CHEATS_LIST cheat; u32 chsize = cheats->getListSize();