menu: fix segfault with toplevel <separator>

Before this patch, labwc crashed menu.xml like this:

<openbox_menu>
  <separator />
</openbox_menu>
This commit is contained in:
tokyo4j 2025-08-03 16:55:59 +09:00 committed by Johan Malm
parent 00ed40454d
commit 03004cf44b

View file

@ -269,6 +269,8 @@ item_create_scene(struct menuitem *menuitem, int *item_y)
static struct menuitem *
separator_create(struct menu *menu, const char *label)
{
assert(menu);
struct menuitem *menuitem = znew(*menuitem);
menuitem->parent = menu;
menuitem->selectable = false;
@ -754,6 +756,11 @@ xml_tree_walk(struct menu_parse_context *ctx, xmlNode *node)
continue;
}
if (!strcasecmp((char *)n->name, "separator")) {
if (!ctx->menu) {
wlr_log(WLR_ERROR,
"ignoring <separator> without parent <menu>");
continue;
}
handle_separator_element(ctx, n);
continue;
}