Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Bug Report: al_build_menu() segfault

This thread is locked; no one can reply to it. rss feed Print
Bug Report: al_build_menu() segfault
DankestOfMemers
Member #16,281
April 2016

I'm on Arch Linux with gcc 5.3.0 and Allegro 5.2.0.0. I noticed that al_build_menu() was causing my program to segfault. So I fired up gdb and found that parse_menu_info() was reading one entry past the ALLEGRO_END_OF_MENU terminator, causing an uninitialized read in strlen() and therefore a segfault. I temporarily fixed this by adding a second ALLEGRO_END_OF_MENU to the array, but it would be nice if this could get fixed.

SiegeLord
Member #7,827
October 2006
avatar

Filed https://github.com/liballeg/allegro5/issues/615. Indeed, it appears to be a legitimate bug.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

DankestOfMemers
Member #16,281
April 2016

Thanks. Allegro has been immensely helpful to me for my game. I appreciate what you guys are doing here.

SiegeLord
Member #7,827
October 2006
avatar

I looked into this, and I think this might work as intended (although the segfault is unfortunate). It appears that both in the documentation and in the examples you do indeed need to have two `ALLEGRO_END_OF_MENU`s, one for the sub-menu and one for the rest of the menu:

#SelectExpand
1ALLEGRO_MENU_INFO main_menu_info[] = { 2 ALLEGRO_START_OF_MENU("&File", FILE_ID), 3 { "&Open", FILE_OPEN_ID, 0, NULL }, 4 ALLEGRO_MENU_SEPARATOR, 5 { "E&xit", FILE_EXIT_ID, 0, NULL }, 6 ALLEGRO_END_OF_MENU, 7 8 ALLEGRO_START_OF_MENU("&Dynamic Options", DYNAMIC_ID), 9 { "&Checkbox", DYNAMIC_CHECKBOX_ID, ALLEGRO_MENU_ITEM_CHECKED, NULL }, 10 { "&Disabled", DYNAMIC_DISABLED_ID, ALLEGRO_MENU_ITEM_DISABLED, NULL }, 11 { "DELETE ME!", DYNAMIC_DELETE_ID, 0, NULL }, 12 { "Click Me", DYNAMIC_CREATE_ID, 0, NULL }, 13 ALLEGRO_END_OF_MENU, 14 15 ALLEGRO_START_OF_MENU("&Help", 0), 16 { "&About", HELP_ABOUT_ID, 0, NULL }, 17 ALLEGRO_END_OF_MENU, 18 19 ALLEGRO_END_OF_MENU 20};

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Go to: