Fix NULL after deref issue detected by static analysis tool
[platform/upstream/libxkbcommon.git] / src / xkbcomp / types.c
index e8e82df..fa12c23 100644 (file)
@@ -144,6 +144,7 @@ AddKeyType(KeyTypesInfo *info, KeyTypeInfo *new, bool same_file)
         if (new->merge == MERGE_REPLACE || new->merge == MERGE_OVERRIDE) {
             if ((same_file && verbosity > 0) || verbosity > 9) {
                 log_warn(info->ctx,
+                         XKB_WARNING_CONFLICTING_KEY_TYPE_DEFINITIONS,
                          "Multiple definitions of the %s key type; "
                          "Earlier definition ignored\n",
                          xkb_atom_text(info->ctx, new->name));
@@ -158,6 +159,7 @@ AddKeyType(KeyTypesInfo *info, KeyTypeInfo *new, bool same_file)
 
         if (same_file)
             log_vrb(info->ctx, 4,
+                    XKB_WARNING_CONFLICTING_KEY_TYPE_DEFINITIONS,
                     "Multiple definitions of the %s key type; "
                     "Later definition ignored\n",
                     xkb_atom_text(info->ctx, new->name));
@@ -210,6 +212,9 @@ HandleIncludeKeyTypes(KeyTypesInfo *info, IncludeStmt *include)
 {
     KeyTypesInfo included;
 
+    if (!include)
+        return false;
+
     InitKeyTypesInfo(&included, info->ctx, &info->mods);
     included.name = include->stmt;
     include->stmt = NULL;
@@ -250,19 +255,20 @@ SetModifiers(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
     xkb_mod_mask_t mods;
 
     if (arrayNdx)
-        log_warn(info->ctx,
+        log_warn(info->ctx, XKB_LOG_MESSAGE_NO_ID,
                  "The modifiers field of a key type is not an array; "
                  "Illegal array subscript ignored\n");
 
     if (!ExprResolveModMask(info->ctx, value, MOD_BOTH, &info->mods, &mods)) {
         log_err(info->ctx,
+                XKB_ERROR_UNSUPPORTED_MODIFIER_MASK,
                 "Key type mask field must be a modifier mask; "
                 "Key type definition ignored\n");
         return false;
     }
 
     if (type->defined & TYPE_FIELD_MASK) {
-        log_warn(info->ctx,
+        log_warn(info->ctx, XKB_LOG_MESSAGE_NO_ID,
                  "Multiple modifier mask definitions for key type %s; "
                  "Using %s, ignoring %s\n",
                  xkb_atom_text(info->ctx, type->name),
@@ -299,6 +305,7 @@ AddMapEntry(KeyTypesInfo *info, KeyTypeInfo *type,
     if (old) {
         if (report && old->level != new->level) {
             log_warn(info->ctx,
+                     XKB_WARNING_CONFLICTING_KEY_TYPE_MAP_ENTRY,
                      "Multiple map entries for %s in %s; "
                      "Using %d, ignoring %d\n",
                      MapEntryTxt(info, new), TypeTxt(info, type),
@@ -307,6 +314,7 @@ AddMapEntry(KeyTypesInfo *info, KeyTypeInfo *type,
         }
         else {
             log_vrb(info->ctx, 10,
+                    XKB_WARNING_CONFLICTING_KEY_TYPE_MAP_ENTRY,
                     "Multiple occurrences of map[%s]= %d in %s; Ignored\n",
                     MapEntryTxt(info, new), new->level + 1,
                     TypeTxt(info, type));
@@ -345,7 +353,8 @@ SetMapEntry(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
 
     if (entry.mods.mods & (~type->mods)) {
         log_vrb(info->ctx, 1,
-                "Map entry for unused modifiers in %s; "
+                XKB_WARNING_UNDECLARED_MODIFIERS_IN_KEY_TYPE,
+                "Map entry for modifiers not used by type %s; "
                 "Using %s instead of %s\n",
                 TypeTxt(info, type),
                 ModMaskText(info->ctx, &info->mods,
@@ -355,7 +364,7 @@ SetMapEntry(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
     }
 
     if (!ExprResolveLevel(info->ctx, value, &entry.level)) {
-        log_err_with_code(info->ctx, XKB_ERROR_UNSUPPORTED_SHIFT_LEVEL,
+        log_err(info->ctx, XKB_ERROR_UNSUPPORTED_SHIFT_LEVEL,
                           "Level specifications in a key type must be integer; "
                           "Ignoring malformed level specification\n");
         return false;
@@ -388,6 +397,7 @@ AddPreserve(KeyTypesInfo *info, KeyTypeInfo *type,
         /* Map exists with same preserve; do nothing. */
         if (entry->preserve.mods == preserve_mods) {
             log_vrb(info->ctx, 10,
+                    XKB_WARNING_DUPLICATE_ENTRY,
                     "Identical definitions for preserve[%s] in %s; "
                     "Ignored\n",
                     ModMaskText(info->ctx, &info->mods, mods),
@@ -397,6 +407,7 @@ AddPreserve(KeyTypesInfo *info, KeyTypeInfo *type,
 
         /* Map exists with different preserve; latter wins. */
         log_vrb(info->ctx, 1,
+                XKB_WARNING_CONFLICTING_KEY_TYPE_PRESERVE_ENTRIES,
                 "Multiple definitions for preserve[%s] in %s; "
                 "Using %s, ignoring %s\n",
                 ModMaskText(info->ctx, &info->mods, mods),
@@ -441,7 +452,8 @@ SetPreserve(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
         after = ModMaskText(info->ctx, &info->mods, mods);
 
         log_vrb(info->ctx, 1,
-                "Preserve for modifiers not used by the %s type; "
+                XKB_WARNING_UNDECLARED_MODIFIERS_IN_KEY_TYPE,
+                "Preserve entry for modifiers not used by the %s type; "
                 "Index %s converted to %s\n",
                 TypeTxt(info, type), before, after);
     }
@@ -449,6 +461,7 @@ SetPreserve(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
     if (!ExprResolveModMask(info->ctx, value, MOD_BOTH, &info->mods,
                             &preserve_mods)) {
         log_err(info->ctx,
+                XKB_ERROR_UNSUPPORTED_MODIFIER_MASK,
                 "Preserve value in a key type is not a modifier mask; "
                 "Ignoring preserve[%s] in type %s\n",
                 ModMaskText(info->ctx, &info->mods, mods),
@@ -464,6 +477,7 @@ SetPreserve(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
         after = ModMaskText(info->ctx, &info->mods, preserve_mods);
 
         log_vrb(info->ctx, 1,
+                XKB_WARNING_ILLEGAL_KEY_TYPE_PRESERVE_RESULT,
                 "Illegal value for preserve[%s] in type %s; "
                 "Converted %s to %s\n",
                 ModMaskText(info->ctx, &info->mods, mods),
@@ -488,6 +502,7 @@ AddLevelName(KeyTypesInfo *info, KeyTypeInfo *type,
     /* Same level, same name. */
     if (darray_item(type->level_names, level) == name) {
         log_vrb(info->ctx, 10,
+                XKB_WARNING_DUPLICATE_ENTRY,
                 "Duplicate names for level %d of key type %s; Ignored\n",
                 level + 1, TypeTxt(info, type));
         return true;
@@ -500,6 +515,7 @@ AddLevelName(KeyTypesInfo *info, KeyTypeInfo *type,
                             darray_item(type->level_names, level));
         new = xkb_atom_text(info->ctx, name);
         log_vrb(info->ctx, 1,
+                XKB_WARNING_CONFLICTING_KEY_TYPE_LEVEL_NAMES,
                 "Multiple names for level %d of key type %s; "
                 "Using %s, ignoring %s\n",
                 level + 1, TypeTxt(info, type),
@@ -532,6 +548,7 @@ SetLevelName(KeyTypesInfo *info, KeyTypeInfo *type, ExprDef *arrayNdx,
 
     if (!ExprResolveString(info->ctx, value, &level_name)) {
         log_err(info->ctx,
+                XKB_ERROR_WRONG_FIELD_TYPE,
                 "Non-string name for level %d in key type %s; "
                 "Ignoring illegal level name definition\n",
                 level + 1, xkb_atom_text(info->ctx, type->name));
@@ -567,6 +584,7 @@ SetKeyTypeField(KeyTypesInfo *info, KeyTypeInfo *type,
         ok = SetLevelName(info, type, arrayNdx, value);
     } else {
         log_err(info->ctx,
+                XKB_ERROR_UNKNOWN_FIELD,
                 "Unknown field %s in key type %s; Definition ignored\n",
                 field, TypeTxt(info, type));
     }
@@ -590,6 +608,7 @@ HandleKeyTypeBody(KeyTypesInfo *info, VarDef *def, KeyTypeInfo *type)
 
         if (elem && istreq(elem, "type")) {
             log_err(info->ctx,
+                    XKB_ERROR_INVALID_SET_DEFAULT_STATEMENT,
                     "Support for changing the default type has been removed; "
                     "Statement ignored\n");
             continue;
@@ -645,6 +664,7 @@ HandleKeyTypesFile(KeyTypesInfo *info, XkbFile *file, enum merge_mode merge)
             break;
         case STMT_VAR:
             log_err(info->ctx,
+                    XKB_ERROR_WRONG_STATEMENT_TYPE,
                     "Support for changing the default type has been removed; "
                     "Statement ignored\n");
             ok = true;
@@ -654,6 +674,7 @@ HandleKeyTypesFile(KeyTypesInfo *info, XkbFile *file, enum merge_mode merge)
             break;
         default:
             log_err(info->ctx,
+                    XKB_ERROR_WRONG_STATEMENT_TYPE,
                     "Key type files may not include other declarations; "
                     "Ignoring %s\n", stmt_type_to_string(stmt->type));
             ok = false;
@@ -665,6 +686,7 @@ HandleKeyTypesFile(KeyTypesInfo *info, XkbFile *file, enum merge_mode merge)
 
         if (info->errorCount > 10) {
             log_err(info->ctx,
+                    XKB_ERROR_INVALID_SYNTAX,
                     "Abandoning keytypes file \"%s\"\n", file->name);
             break;
         }