]> git.mdlowis.com Git - proto/labwc.git/commitdiff
menu: do not modify literal string constants
authorJohn Lindgren <john@jlindgren.net>
Fri, 4 Jul 2025 03:35:37 +0000 (23:35 -0400)
committerConsolatis <35009135+Consolatis@users.noreply.github.com>
Mon, 21 Jul 2025 14:51:10 +0000 (16:51 +0200)
Mutable string literals are a "legacy" C feature best avoided.

v2: move string_truncate_at_pattern() outside fill_item()

src/menu/menu.c

index c89c2b888f114360856ac5949001963d485546fa..461c31539db3a9bca0266a5604cb80e0fc7c275f 100644 (file)
@@ -467,16 +467,8 @@ menu_create_scene(struct menu *menu)
  * </item>
  */
 static void
-fill_item(char *nodename, char *content)
+fill_item(const char *nodename, const char *content)
 {
-       /*
-        * Nodenames for most menu-items end with '.item.menu' but top-level
-        * pipemenu items do not have the associated <menu> element so merely
-        * end with a '.item'
-        */
-       string_truncate_at_pattern(nodename, ".item.menu");
-       string_truncate_at_pattern(nodename, ".item");
-
        /* <item label=""> defines the start of a new item */
        if (!strcmp(nodename, "label")) {
                current_item = item_create(current_menu, content, false);
@@ -572,6 +564,13 @@ entry(xmlNode *node, char *nodename, char *content)
                printf("%s: %s\n", nodename, content ? content : (char *)cdata);
        }
        if (in_item) {
+               /*
+                * Nodenames for most menu-items end with '.item.menu'
+                * but top-level pipemenu items do not have the associated
+                * <menu> element so merely end with '.item'
+                */
+               string_truncate_at_pattern(nodename, ".item.menu");
+               string_truncate_at_pattern(nodename, ".item");
                fill_item(nodename, content ? content : (char *)cdata);
        }
        xmlFree(cdata);