From 64575f2aed9b8f205a6dc1c721e441197c1c2e1f Mon Sep 17 00:00:00 2001 From: Chris Young Date: Mon, 29 Feb 2016 18:10:45 +0000 Subject: [PATCH] Avoid some crashing by disabling the update of the hotlist menu This will be fixed properly when the menu code is re-written to use menuclass, as that supports dynamic updates. --- amiga/font_diskfont.c | 1 + amiga/gui.c | 2 +- amiga/menu.c | 26 +++++++++++++++++--------- amiga/tree.c | 2 ++ 4 files changed, 21 insertions(+), 10 deletions(-) diff --git a/amiga/font_diskfont.c b/amiga/font_diskfont.c index 20b69856b..6beae57ff 100644 --- a/amiga/font_diskfont.c +++ b/amiga/font_diskfont.c @@ -103,6 +103,7 @@ static size_t ami_font_bm_convert_local_to_utf8_offset(const char *utf8string, s for(UWORD i = 0; i < offset; i++) { chr = utf8_next(utf8string, length, chr); + if(chr > length) return length; } return chr; diff --git a/amiga/gui.c b/amiga/gui.c index 988111151..e63812976 100644 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -3739,7 +3739,7 @@ HOOKF(void, ami_scroller_hook, Object *, object, struct IntuiMessage *) break; default: - LOG("IDCMP hook unhandled event: %d\n", msg->Class); + LOG("IDCMP hook unhandled event: %ld\n", msg->Class); break; } // ReplyMsg((struct Message *)msg); diff --git a/amiga/menu.c b/amiga/menu.c index 08b2aed25..646039a30 100644 --- a/amiga/menu.c +++ b/amiga/menu.c @@ -43,6 +43,7 @@ #include "utils/nsoption.h" #include "utils/messages.h" +#include "utils/log.h" #include "desktop/hotlist.h" #include "desktop/browser.h" @@ -516,7 +517,7 @@ void ami_free_menulabs(struct gui_window_2 *gwin) { int i; - for(i=0;i<=AMI_MENU_AREXX_MAX;i++) { + for(i=0;imenulab[i] && (gwin->menulab[i] != NM_BARLABEL)) { if(gwin->menutype[i] & MENU_IMAGE) { if(gwin->menuobj[i]) DisposeObject(gwin->menuobj[i]); @@ -526,6 +527,7 @@ void ami_free_menulabs(struct gui_window_2 *gwin) if(i >= AMI_MENU_AREXX) { if(gwin->menu_hook[i].h_Data) free(gwin->menu_hook[i].h_Data); + gwin->menu_hook[i].h_Data = NULL; } } @@ -535,10 +537,7 @@ void ami_free_menulabs(struct gui_window_2 *gwin) } FreeVec(gwin->menutype); - FreeVec(gwin->menu); - gwin->menutype = NULL; - gwin->menu = NULL; } static void ami_menu_alloc_item(struct gui_window_2 *gwin, int num, UBYTE type, @@ -555,7 +554,7 @@ static void ami_menu_alloc_item(struct gui_window_2 *gwin, int num, UBYTE type, utf8_from_local_encoding(label, (strlen(label) < NSA_MAX_HOTLIST_MENU_LEN) ? strlen(label) : NSA_MAX_HOTLIST_MENU_LEN, &gwin->menulab[num]); - } else if((num >= AMI_MENU_AREXX) && (num <= AMI_MENU_AREXX_MAX)) { + } else if((num >= AMI_MENU_AREXX) && (num < AMI_MENU_AREXX_MAX)) { gwin->menulab[num] = strdup(label); } else { gwin->menulab[num] = ami_utf8_easy(messages_get(label)); @@ -585,13 +584,14 @@ static void ami_init_menulabs(struct gui_window_2 *gwin) { int i; - gwin->menutype = ami_misc_allocvec_clear(AMI_MENU_AREXX_MAX + 1, 0); + gwin->menutype = ami_misc_allocvec_clear(sizeof(UBYTE) * (AMI_MENU_AREXX_MAX + 1), 0); for(i=0;i <= AMI_MENU_AREXX_MAX;i++) { gwin->menutype[i] = NM_IGNORE; gwin->menulab[i] = NULL; gwin->menuobj[i] = NULL; + gwin->menuicon[i] = NULL; } ami_menu_alloc_item(gwin, M_PROJECT, NM_TITLE, "Project", 0, NULL, NULL, NULL); @@ -704,17 +704,25 @@ static void ami_init_menulabs(struct gui_window_2 *gwin) /* Menu refresh for hotlist */ void ami_menu_refresh(struct gui_window_2 *gwin) { + return; /**\todo fix this after migrating to menuclass */ + struct Menu *menu; + LOG("Clearing MenuStrip"); SetAttrs(gwin->objects[OID_MAIN], WINDOW_MenuStrip, NULL, TAG_DONE); + LOG("Freeing menu"); ami_menu_free(gwin); + + LOG("Freeing menu labels"); ami_free_menulabs(gwin); + LOG("Creating new menu"); menu = ami_menu_create(gwin); + LOG("Attaching MenuStrip %p to %p", menu, gwin->objects[OID_MAIN]); SetAttrs(gwin->objects[OID_MAIN], WINDOW_MenuStrip, menu, TAG_DONE); @@ -801,7 +809,7 @@ static struct gui_window_2 *ami_menu_layout(struct gui_window_2 *gwin) if(menu_glyphs_loaded == false) ami_menu_load_glyphs(dri); - for(i=0; i <= AMI_MENU_AREXX_MAX; i++) + for(i=0; i < AMI_MENU_AREXX_MAX; i++) { if(gwin->menutype[i] == NM_TITLE) { j = i + 1; @@ -926,8 +934,8 @@ struct Menu *ami_menu_create(struct gui_window_2 *gwin) gwin->imenu = CreateMenus(gwin->menu, TAG_DONE); LayoutMenus(gwin->imenu, gwin->vi, GTMN_NewLookMenus, TRUE, TAG_DONE); - - /**\todo do we even need to store/keep gwin->menu? **/ + FreeVec(gwin->menu); /**\todo this should be local to this function */ + gwin->menu = NULL; return gwin->imenu; } diff --git a/amiga/tree.c b/amiga/tree.c index 5307c6e8d..fd0a5a61e 100644 --- a/amiga/tree.c +++ b/amiga/tree.c @@ -672,12 +672,14 @@ static void ami_tree_menu(struct treeview_window *twin) twin->menu[24].nm_Label = twin->menu_name[24]; twin->menu[25].nm_Type = NM_END; + twin->menu_name[25] = NULL; } } static void ami_tree_update_buttons(struct treeview_window *twin) { if(twin->type == AMI_TREE_SSLCERT) return; + if(twin->menu == NULL) return; if(twin->type != AMI_TREE_HOTLIST) { OffMenu(twin->win, AMI_TREE_MENU_NEWDIR);