From: Daniel Liu Date: Sat, 6 Feb 2021 20:56:06 +0000 (-0500) Subject: so apparently heap array not contiguous X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=c2cc205fd4d6e73e1ee2e4ed1136dd9e291754d4;p=taskasaur.git so apparently heap array not contiguous --- diff --git a/menu.c b/menu.c index 67ca8e2..71bb5a0 100644 --- a/menu.c +++ b/menu.c @@ -172,8 +172,9 @@ insert_item(Menu* menu, int index) /* resize array and insert */ menu->menu_items = realloc(menu->menu_items, (menu->menu_length+2)*sizeof(MenuItem*)); - int temp_size = menu->menu_length-index*sizeof(MenuItem*); - memmove(menu->menu_items[index], menu->menu_items[index+1], temp_size); + for (int i = menu->menu_length; i > index; i--) { + menu->menu_items[i] = menu->menu_items[i-1]; + } menu->menu_items[index] = new_menuitem; menu->menu_items[menu->menu_length+1] = 0; // remember null at end @@ -227,7 +228,7 @@ menu_driver(Menu* menu, MenuAction action) /* curs_on(); */ /* curs_off(); */ /* insert_item(menu, menu->selected_item); */ - insert_item(menu, 0); + insert_item(menu, menu->selected_item); wclear(menu->sub_win); break;