diff -Nru libxkbcommon-0.8.0.orig/src/xkbcomp/ast-build.c libxkbcommon-0.8.0/src/xkbcomp/ast-build.c
--- libxkbcommon-0.8.0.orig/src/xkbcomp/ast-build.c	2017-12-12 13:40:28.000000000 +0100
+++ libxkbcommon-0.8.0/src/xkbcomp/ast-build.c	2025-06-06 15:35:33.571894817 +0200
@@ -72,7 +72,7 @@
 static ExprDef *
 ExprCreate(enum expr_op_type op, enum expr_value_type type, size_t size)
 {
-    ExprDef *expr = malloc(size);
+    ExprDef *expr = malloc(sizeof(ExprDef));
     if (!expr)
         return NULL;
 
@@ -84,15 +84,12 @@
     return expr;
 }
 
-#define EXPR_CREATE(type_, name_, op_, value_type_) \
-    ExprDef *name_ = ExprCreate(op_, value_type_, sizeof(type_)); \
-    if (!name_) \
-        return NULL;
-
 ExprDef *
 ExprCreateString(xkb_atom_t str)
 {
-    EXPR_CREATE(ExprString, expr, EXPR_VALUE, EXPR_TYPE_STRING);
+    ExprDef *expr = ExprCreate(EXPR_VALUE, EXPR_TYPE_STRING, sizeof(ExprString));
+    if (!expr)
+        return NULL;
     expr->string.str = str;
     return expr;
 }
@@ -100,7 +97,9 @@
 ExprDef *
 ExprCreateInteger(int ival)
 {
-    EXPR_CREATE(ExprInteger, expr, EXPR_VALUE, EXPR_TYPE_INT);
+    ExprDef *expr = ExprCreate(EXPR_VALUE, EXPR_TYPE_INT, sizeof(ExprInteger));
+    if (!expr)
+        return NULL;
     expr->integer.ival = ival;
     return expr;
 }
@@ -108,7 +107,9 @@
 ExprDef *
 ExprCreateBoolean(bool set)
 {
-    EXPR_CREATE(ExprBoolean, expr, EXPR_VALUE, EXPR_TYPE_BOOLEAN);
+    ExprDef *expr = ExprCreate(EXPR_VALUE, EXPR_TYPE_BOOLEAN, sizeof(ExprBoolean));
+    if (!expr)
+        return NULL;
     expr->boolean.set = set;
     return expr;
 }
@@ -116,7 +117,9 @@
 ExprDef *
 ExprCreateKeyName(xkb_atom_t key_name)
 {
-    EXPR_CREATE(ExprKeyName, expr, EXPR_VALUE, EXPR_TYPE_KEYNAME);
+    ExprDef *expr = ExprCreate(EXPR_VALUE, EXPR_TYPE_KEYNAME, sizeof(ExprKeyName));
+    if (!expr)
+        return NULL;
     expr->key_name.key_name = key_name;
     return expr;
 }
@@ -124,7 +127,9 @@
 ExprDef *
 ExprCreateIdent(xkb_atom_t ident)
 {
-    EXPR_CREATE(ExprIdent, expr, EXPR_IDENT, EXPR_TYPE_UNKNOWN);
+    ExprDef *expr = ExprCreate(EXPR_IDENT, EXPR_TYPE_UNKNOWN, sizeof(ExprIdent));
+    if (!expr)
+        return NULL;
     expr->ident.ident = ident;
     return expr;
 }
@@ -133,7 +138,9 @@
 ExprCreateUnary(enum expr_op_type op, enum expr_value_type type,
                 ExprDef *child)
 {
-    EXPR_CREATE(ExprUnary, expr, op, type);
+    ExprDef *expr = ExprCreate(op, type, sizeof(ExprUnary));
+    if (!expr)
+        return NULL;
     expr->unary.child = child;
     return expr;
 }
@@ -141,7 +148,9 @@
 ExprDef *
 ExprCreateBinary(enum expr_op_type op, ExprDef *left, ExprDef *right)
 {
-    EXPR_CREATE(ExprBinary, expr, op, EXPR_TYPE_UNKNOWN);
+    ExprDef *expr = ExprCreate(op, EXPR_TYPE_UNKNOWN, sizeof(ExprBinary));
+    if (!expr)
+        return NULL;
 
     if (op == EXPR_ASSIGN || left->expr.value_type == EXPR_TYPE_UNKNOWN)
         expr->expr.value_type = right->expr.value_type;
@@ -157,7 +166,9 @@
 ExprDef *
 ExprCreateFieldRef(xkb_atom_t element, xkb_atom_t field)
 {
-    EXPR_CREATE(ExprFieldRef, expr, EXPR_FIELD_REF, EXPR_TYPE_UNKNOWN);
+    ExprDef *expr = ExprCreate(EXPR_FIELD_REF, EXPR_TYPE_UNKNOWN, sizeof(ExprFieldRef));
+    if (!expr)
+        return NULL;
     expr->field_ref.element = element;
     expr->field_ref.field = field;
     return expr;
@@ -166,7 +177,9 @@
 ExprDef *
 ExprCreateArrayRef(xkb_atom_t element, xkb_atom_t field, ExprDef *entry)
 {
-    EXPR_CREATE(ExprArrayRef, expr, EXPR_ARRAY_REF, EXPR_TYPE_UNKNOWN);
+    ExprDef *expr = ExprCreate(EXPR_ARRAY_REF, EXPR_TYPE_UNKNOWN, sizeof(ExprArrayRef));
+    if (!expr)
+        return NULL;
     expr->array_ref.element = element;
     expr->array_ref.field = field;
     expr->array_ref.entry = entry;
@@ -176,7 +189,9 @@
 ExprDef *
 ExprCreateAction(xkb_atom_t name, ExprDef *args)
 {
-    EXPR_CREATE(ExprAction, expr, EXPR_ACTION_DECL, EXPR_TYPE_UNKNOWN);
+    ExprDef *expr = ExprCreate(EXPR_ACTION_DECL, EXPR_TYPE_UNKNOWN, sizeof(ExprAction));
+    if (!expr)
+        return NULL;
     expr->action.name = name;
     expr->action.args = args;
     return expr;
@@ -185,7 +200,9 @@
 ExprDef *
 ExprCreateKeysymList(xkb_keysym_t sym)
 {
-    EXPR_CREATE(ExprKeysymList, expr, EXPR_KEYSYM_LIST, EXPR_TYPE_SYMBOLS);
+    ExprDef *expr = ExprCreate(EXPR_KEYSYM_LIST, EXPR_TYPE_SYMBOLS, sizeof(ExprKeysymList));
+    if (!expr)
+        return NULL;
 
     darray_init(expr->keysym_list.syms);
     darray_init(expr->keysym_list.symsMapIndex);
@@ -233,7 +250,7 @@
     darray_append(expr->keysym_list.symsNumEntries, numEntries);
     darray_concat(expr->keysym_list.syms, append->keysym_list.syms);
 
-    FreeStmt((ParseCommon *) &append);
+    FreeStmt((ParseCommon *) append);
 
     return expr;
 }
@@ -438,15 +455,16 @@
 IncludeCreate(struct xkb_context *ctx, char *str, enum merge_mode merge)
 {
     IncludeStmt *incl, *first;
-    char *file, *map, *stmt, *tmp, *extra_data;
+    char *stmt, *tmp;
     char nextop;
 
     incl = first = NULL;
-    file = map = NULL;
     tmp = str;
     stmt = strdup_safe(str);
     while (tmp && *tmp)
     {
+        char *file = NULL, *map = NULL, *extra_data = NULL;
+
         if (!ParseIncludeMap(&tmp, &file, &map, &nextop, &extra_data))
             goto err;
 
@@ -470,8 +488,12 @@
             incl = incl->next_incl;
         }
 
-        if (!incl)
+        if (!incl) {
+            free(file);
+            free(map);
+            free(extra_data);
             break;
+        }
 
         incl->common.type = STMT_INCLUDE;
         incl->common.next = NULL;
@@ -532,7 +554,7 @@
     enum xkb_file_type type;
     IncludeStmt *include = NULL;
     XkbFile *file = NULL;
-    ParseCommon *defs = NULL;
+    ParseCommon *defs = NULL, *defsLast = NULL;
 
     for (type = FIRST_KEYMAP_FILE_TYPE; type <= LAST_KEYMAP_FILE_TYPE; type++) {
         include = IncludeCreate(ctx, components[type], MERGE_DEFAULT);
@@ -545,7 +567,10 @@
             goto err;
         }
 
-        defs = AppendStmt(defs, &file->common);
+        if (!defs)
+            defsLast = defs = &file->common;
+        else
+            defsLast = defsLast->next = &file->common;
     }
 
     file = XkbFileCreate(FILE_TYPE_KEYMAP, NULL, defs, 0);
@@ -722,7 +747,7 @@
 const char *
 xkb_file_type_to_string(enum xkb_file_type type)
 {
-    if (type > _FILE_TYPE_NUM_ENTRIES)
+    if (type >= _FILE_TYPE_NUM_ENTRIES)
         return "unknown";
     return xkb_file_type_strings[type];
 }
