Commit b2c4331ac365bb7d92cecdb4d6e1f947d8d37d00

Ran Benita 2012-07-28T22:15:59

Handle key names consistently We treat the key names as fixed length, non NUL terminated strings of length XkbKeyNameLength, and use the appropriate *Text functions to print them. We also use strncpy everywhere instead of memcpy to copy the names, because it does some NUL padding and we might as well. Signed-off-by: Ran Benita <ran234@gmail.com>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
diff --git a/src/text.c b/src/text.c
index 1e388ba..6137860 100644
--- a/src/text.c
+++ b/src/text.c
@@ -276,7 +276,7 @@ KeysymText(xkb_keysym_t sym)
 }
 
 const char *
-KeyNameText(char *name)
+KeyNameText(const char name[XkbKeyNameLength])
 {
     char *buf;
     int len;
diff --git a/src/text.h b/src/text.h
index ed677b9..54a7e68 100644
--- a/src/text.h
+++ b/src/text.h
@@ -55,7 +55,7 @@ const char *
 KeysymText(xkb_keysym_t sym);
 
 const char *
-KeyNameText(char *name);
+KeyNameText(const char name[XkbKeyNameLength]);
 
 const char *
 SIMatchText(unsigned type);
diff --git a/src/xkbcomp/expr.c b/src/xkbcomp/expr.c
index d451f67..aaeba28 100644
--- a/src/xkbcomp/expr.c
+++ b/src/xkbcomp/expr.c
@@ -619,7 +619,7 @@ ExprResolveKeyName(struct xkb_context *ctx, const ExprDef *expr,
                     exprValueTypeText(expr->value_type));
             return false;
         }
-        memcpy(name, expr->value.keyName, XkbKeyNameLength);
+        strncpy(name, expr->value.keyName, XkbKeyNameLength);
         return true;
 
     case EXPR_IDENT:
diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c
index f7d873c..5ab59df 100644
--- a/src/xkbcomp/keycodes.c
+++ b/src/xkbcomp/keycodes.c
@@ -121,8 +121,8 @@ typedef struct _AliasInfo {
     unsigned file_id;
     struct list entry;
 
-    char alias[XkbKeyNameLength + 1];
-    char real[XkbKeyNameLength + 1];
+    char alias[XkbKeyNameLength];
+    char real[XkbKeyNameLength];
 } AliasInfo;
 
 typedef struct _IndicatorNameInfo {
@@ -379,8 +379,8 @@ FindKeyByLong(KeyNamesInfo * info, unsigned long name)
  */
 static bool
 AddKeyName(KeyNamesInfo * info,
-           xkb_keycode_t kc, char *name, enum merge_mode merge,
-           unsigned file_id, bool reportCollisions)
+           xkb_keycode_t kc, char name[XkbKeyNameLength],
+           enum merge_mode merge, unsigned file_id, bool reportCollisions)
 {
     xkb_keycode_t old;
     unsigned long lval;
@@ -400,14 +400,13 @@ AddKeyName(KeyNamesInfo * info,
                              file_id == darray_item(info->files, kc)));
 
     if (darray_item(info->names, kc) != 0) {
-        char buf[6];
+        const char *lname = LongKeyNameText(darray_item(info->names, kc));
+        const char *kname = KeyNameText(name);
 
-        LongToKeyName(darray_item(info->names, kc), buf);
-        buf[4] = '\0';
         if (darray_item(info->names, kc) == lval && reportCollisions) {
             log_warn(info->keymap->ctx,
                      "Multiple identical key name definitions; "
-                     "Later occurences of \"<%s> = %d\" ignored\n", buf, kc);
+                     "Later occurences of \"%s = %d\" ignored\n", lname, kc);
             return true;
         }
 
@@ -415,37 +414,40 @@ AddKeyName(KeyNamesInfo * info,
             if (reportCollisions)
                 log_warn(info->keymap->ctx,
                          "Multiple names for keycode %d; "
-                         "Using <%s>, ignoring <%s>\n", kc, buf, name);
+                         "Using %s, ignoring %s\n", kc, lname, kname);
             return true;
         }
         else {
             if (reportCollisions)
                 log_warn(info->keymap->ctx,
                          "Multiple names for keycode %d; "
-                         "Using <%s>, ignoring <%s>\n", kc, name, buf);
+                         "Using %s, ignoring %s\n", kc, kname, lname);
             darray_item(info->names, kc) = 0;
             darray_item(info->files, kc) = 0;
         }
     }
 
     old = FindKeyByLong(info, lval);
-    if ((old != 0) && (old != kc)) {
+    if (old != 0 && old != kc) {
+        const char *kname = KeyNameText(name);
+
         if (merge == MERGE_OVERRIDE) {
             darray_item(info->names, old) = 0;
             darray_item(info->files, old) = 0;
             if (reportCollisions)
                 log_warn(info->keymap->ctx,
-                         "Key name <%s> assigned to multiple keys; "
-                         "Using %d, ignoring %d\n", name, kc, old);
+                         "Key name %s assigned to multiple keys; "
+                         "Using %d, ignoring %d\n", kname, kc, old);
         }
         else {
             if (reportCollisions && verbosity > 3)
                 log_warn(info->keymap->ctx,
-                         "Key name <%s> assigned to multiple keys; "
-                         "Using %d, ignoring %d\n", name, old, kc);
+                         "Key name %s assigned to multiple keys; "
+                         "Using %d, ignoring %d\n", kname, old, kc);
             return true;
         }
     }
+
     darray_item(info->names, kc) = lval;
     darray_item(info->files, kc) = file_id;
     return true;
@@ -476,8 +478,8 @@ MergeAliases(KeyNamesInfo *into, KeyNamesInfo *from, enum merge_mode merge)
 
     list_foreach_safe(alias, next, &from->aliases, entry) {
         def.merge = (merge == MERGE_DEFAULT) ? alias->merge : merge;
-        memcpy(def.alias, alias->alias, XkbKeyNameLength);
-        memcpy(def.real, alias->real, XkbKeyNameLength);
+        strncpy(def.alias, alias->alias, XkbKeyNameLength);
+        strncpy(def.real, alias->real, XkbKeyNameLength);
 
         if (!HandleAliasDef(into, &def, def.merge, alias->file_id))
             return false;
@@ -491,7 +493,7 @@ MergeIncludedKeycodes(KeyNamesInfo *into, KeyNamesInfo *from,
                       enum merge_mode merge)
 {
     uint64_t i;
-    char buf[5];
+    char buf[XkbKeyNameLength];
     IndicatorNameInfo *led;
 
     if (from->errorCount > 0) {
@@ -509,7 +511,6 @@ MergeIncludedKeycodes(KeyNamesInfo *into, KeyNamesInfo *from,
         if (darray_item(from->names, i) == 0)
             continue;
         LongToKeyName(darray_item(from->names, i), buf);
-        buf[4] = '\0';
         if (!AddKeyName(into, i, buf, merge, from->file_id, false))
             into->errorCount++;
     }
@@ -599,9 +600,9 @@ HandleKeycodeDef(KeyNamesInfo *info, KeycodeDef *stmt, enum merge_mode merge)
     if ((info->explicitMin != 0 && stmt->value < info->explicitMin) ||
         (info->explicitMax != 0 && stmt->value > info->explicitMax)) {
         log_err(info->keymap->ctx,
-                "Illegal keycode %lu for name <%s>; "
+                "Illegal keycode %lu for name %s; "
                 "Must be in the range %d-%d inclusive\n",
-                stmt->value, stmt->name, info->explicitMin,
+                stmt->value, KeyNameText(stmt->name), info->explicitMin,
                 info->explicitMax ? info->explicitMax : XKB_KEYCODE_MAX);
         return 0;
     }
@@ -647,7 +648,7 @@ HandleAliasCollision(KeyNamesInfo *info, AliasInfo *old, AliasInfo *new)
                      KeyNameText(ignore));
 
         if (use != old->real)
-            memcpy(old->real, use, XkbKeyNameLength);
+            strncpy(old->real, use, XkbKeyNameLength);
     }
 
     old->file_id = new->file_id;
@@ -677,8 +678,8 @@ HandleAliasDef(KeyNamesInfo *info, KeyAliasDef *def, enum merge_mode merge,
 
     alias->file_id = file_id;
     alias->merge = merge;
-    memcpy(alias->alias, def->alias, XkbKeyNameLength);
-    memcpy(alias->real, def->real, XkbKeyNameLength);
+    strncpy(alias->alias, def->alias, XkbKeyNameLength);
+    strncpy(alias->real, def->real, XkbKeyNameLength);
     list_append(&alias->entry, &info->aliases);
 
     return true;
@@ -929,7 +930,7 @@ ApplyAliases(KeyNamesInfo *info)
 
             InitAliasInfo(&old_alias, MERGE_AUGMENT, 0, a->alias, a->real);
             HandleAliasCollision(info, &old_alias, alias);
-            memcpy(old_alias.real, a->real, XkbKeyNameLength);
+            strncpy(old_alias.real, a->real, XkbKeyNameLength);
             alias->alias[0] = '\0';
             nNew--;
             break;
diff --git a/src/xkbcomp/misc.c b/src/xkbcomp/misc.c
index 4742a4e..4db4ac2 100644
--- a/src/xkbcomp/misc.c
+++ b/src/xkbcomp/misc.c
@@ -144,9 +144,7 @@ FindNamedKey(struct xkb_keymap *keymap, unsigned long name,
         /* Find first unused key and store our key here */
         xkb_foreach_key(key, keymap) {
             if (key->name[0] == '\0') {
-                char buf[XkbKeyNameLength + 1];
-                LongToKeyName(name, buf);
-                memcpy(key->name, buf, XkbKeyNameLength);
+                LongToKeyName(name, key->name);
                 return key;
             }
         }
@@ -159,11 +157,10 @@ bool
 FindKeyNameForAlias(struct xkb_keymap *keymap, unsigned long lname,
                     unsigned long *real_name)
 {
-    char name[XkbKeyNameLength + 1];
+    char name[XkbKeyNameLength];
     struct xkb_key_alias *a;
 
     LongToKeyName(lname, name);
-    name[XkbKeyNameLength] = '\0';
     darray_foreach(a, keymap->key_aliases) {
         if (strncmp(name, a->alias, XkbKeyNameLength) == 0) {
             *real_name = KeyNameToLong(a->real);
diff --git a/src/xkbcomp/parser.y b/src/xkbcomp/parser.y
index f8b577d..5d8e080 100644
--- a/src/xkbcomp/parser.y
+++ b/src/xkbcomp/parser.y
@@ -681,7 +681,7 @@ Terminal        :       String
                         {
                             ExprDef *expr;
                             expr = ExprCreate(EXPR_VALUE, EXPR_TYPE_KEYNAME);
-                            strncpy(expr->value.keyName, $1, 4);
+                            strncpy(expr->value.keyName, $1, XkbKeyNameLength);
                             $$ = expr;
                         }
                 ;
diff --git a/src/xkbcomp/parseutils.c b/src/xkbcomp/parseutils.c
index 9dbe834..89b7e8d 100644
--- a/src/xkbcomp/parseutils.c
+++ b/src/xkbcomp/parseutils.c
@@ -117,7 +117,6 @@ KeycodeCreate(char keyName[XkbKeyNameLength], unsigned long value)
     def->common.type = STMT_KEYCODE;
     def->common.next = NULL;
     strncpy(def->name, keyName, XkbKeyNameLength);
-    def->name[XkbKeyNameLength] = '\0';
     def->value = value;
     return def;
 }
@@ -132,9 +131,7 @@ KeyAliasCreate(char alias[XkbKeyNameLength], char real[XkbKeyNameLength])
     def->common.type = STMT_ALIAS;
     def->common.next = NULL;
     strncpy(def->alias, alias, XkbKeyNameLength);
-    def->alias[XkbKeyNameLength] = '\0';
     strncpy(def->real, real, XkbKeyNameLength);
-    def->real[XkbKeyNameLength] = '\0';
     return def;
 }
 
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index 83f63da..cda40d4 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -52,15 +52,6 @@ enum key_field {
     KEY_FIELD_VMODMAP   = (1 << 7),
 };
 
-static inline const char *
-longText(unsigned long val)
-{
-    char buf[4];
-
-    LongToKeyName(val, buf);
-    return KeyNameText(buf);
-}
-
 typedef struct _KeyInfo {
     enum key_field defined;
     unsigned file_id;
@@ -355,7 +346,7 @@ MergeKeyGroups(SymbolsInfo * info,
                     log_warn(info->keymap->ctx,
                              "Multiple actions for level %d/group %u on key %s; "
                              "Using %s, ignoring %s\n",
-                             i + 1, group + 1, longText(into->name),
+                             i + 1, group + 1, LongKeyNameText(into->name),
                              ActionTypeText(use->type),
                              ActionTypeText(ignore->type));
                 if (use)
@@ -438,7 +429,7 @@ MergeKeyGroups(SymbolsInfo * info,
             log_info(info->keymap->ctx,
                      "Multiple symbols for group %u, level %d on key %s; "
                      "Using %s, ignoring %s\n",
-                     group + 1, i + 1, longText(into->name),
+                     group + 1, i + 1, LongKeyNameText(into->name),
                      (use == FROM ? "from" : "to"),
                      (use == FROM ? "to" : "from"));
         }
@@ -578,7 +569,7 @@ MergeKeys(SymbolsInfo *info, KeyInfo *into, KeyInfo *from)
                 log_warn(info->keymap->ctx,
                          "Multiple definitions for group %d type of key %s; "
                          "Using %s, ignoring %s\n",
-                         i, longText(into->name),
+                         i, LongKeyNameText(into->name),
                          xkb_atom_text(info->keymap->ctx, use),
                          xkb_atom_text(info->keymap->ctx, ignore));
             }
@@ -616,7 +607,7 @@ MergeKeys(SymbolsInfo *info, KeyInfo *into, KeyInfo *from)
         log_warn(info->keymap->ctx,
                  "Symbol map for key %s redefined; "
                  "Using %s definition for conflicting fields\n",
-                 longText(into->name),
+                 LongKeyNameText(into->name),
                  (from->merge == MERGE_AUGMENT ? "first" : "last"));
 
     return true;
@@ -686,7 +677,7 @@ AddModMapEntry(SymbolsInfo * info, ModMapEntry * new)
                 log_err(info->keymap->ctx,
                         "Key %s added to map for multiple modifiers; "
                         "Using %s, ignoring %s.\n",
-                        longText(new->u.keyName), ModIndexText(use),
+                        LongKeyNameText(new->u.keyName), ModIndexText(use),
                         ModIndexText(ignore));
                 mm->modifier = use;
             }
@@ -830,7 +821,7 @@ GetGroupIndex(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
         log_err(info->keymap->ctx,
                 "Too many groups of %s for key %s (max %u); "
                 "Ignoring %s defined for extra groups\n",
-                name, longText(keyi->name), XkbNumKbdGroups + 1, name);
+                name, LongKeyNameText(keyi->name), XkbNumKbdGroups + 1, name);
         return false;
     }
 
@@ -838,7 +829,7 @@ GetGroupIndex(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
         log_err(info->keymap->ctx,
                 "Illegal group index for %s of key %s\n"
                 "Definition with non-integer array index ignored\n",
-                name, longText(keyi->name));
+                name, LongKeyNameText(keyi->name));
         return false;
     }
 
@@ -866,14 +857,14 @@ AddSymbolsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
         log_err(info->keymap->ctx,
                 "Expected a list of symbols, found %s; "
                 "Ignoring symbols for group %u of %s\n",
-                exprOpText(value->op), ndx + 1, longText(keyi->name));
+                exprOpText(value->op), ndx + 1, LongKeyNameText(keyi->name));
         return false;
     }
     if (!darray_empty(keyi->syms[ndx])) {
         log_err(info->keymap->ctx,
                 "Symbols for key %s, group %u already defined; "
                 "Ignoring duplicate definition\n",
-                longText(keyi->name), ndx + 1);
+                LongKeyNameText(keyi->name), ndx + 1);
         return false;
     }
     nSyms = darray_size(value->value.list.syms);
@@ -883,7 +874,7 @@ AddSymbolsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
         log_wsgo(info->keymap->ctx,
                  "Could not resize group %u of key %s to contain %zu levels; "
                  "Symbols lost\n",
-                 ndx + 1, longText(keyi->name), nSyms);
+                 ndx + 1, LongKeyNameText(keyi->name), nSyms);
         return false;
     }
     keyi->symsDefined |= (1 << ndx);
@@ -906,7 +897,7 @@ AddSymbolsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
                 log_warn(info->keymap->ctx,
                          "Could not resolve keysym %s for key %s, group %u (%s), level %zu\n",
                          darray_item(value->value.list.syms, i),
-                         longText(keyi->name),
+                         LongKeyNameText(keyi->name),
                          ndx + 1,
                          xkb_atom_text(info->keymap->ctx,
                                        info->groupNames[ndx]),
@@ -956,14 +947,14 @@ AddActionsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
         log_wsgo(info->keymap->ctx,
                  "Bad expression type (%d) for action list value; "
                  "Ignoring actions for group %u of %s\n",
-                 value->op, ndx, longText(keyi->name));
+                 value->op, ndx, LongKeyNameText(keyi->name));
         return false;
     }
 
     if (!darray_empty(keyi->acts[ndx])) {
         log_wsgo(info->keymap->ctx,
                  "Actions for key %s, group %u already defined\n",
-                 longText(keyi->name), ndx);
+                 LongKeyNameText(keyi->name), ndx);
         return false;
     }
 
@@ -982,7 +973,7 @@ AddActionsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
         log_wsgo(info->keymap->ctx,
                  "Could not resize group %u of key %s; "
                  "Actions lost\n",
-                 ndx, longText(keyi->name));
+                 ndx, LongKeyNameText(keyi->name));
         return false;
     }
     keyi->actsDefined |= (1 << ndx);
@@ -994,7 +985,7 @@ AddActionsToKey(SymbolsInfo *info, KeyInfo *keyi, ExprDef *arrayNdx,
             log_err(info->keymap->ctx,
                     "Illegal action definition for %s; "
                     "Action for group %u/level %zu ignored\n",
-                    longText(keyi->name), ndx + 1, i + 1);
+                    LongKeyNameText(keyi->name), ndx + 1, i + 1);
         }
         act = (ExprDef *) act->common.next;
     }
@@ -1048,7 +1039,7 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
             log_err(info->keymap->ctx,
                     "Illegal group index for type of key %s; "
                     "Definition with non-integer array index ignored\n",
-                    longText(keyi->name));
+                    LongKeyNameText(keyi->name));
             return false;
         }
         else {
@@ -1075,7 +1066,7 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
             log_err(info->keymap->ctx,
                     "Expected a virtual modifier mask, found %s; "
                     "Ignoring virtual modifiers definition for key %s\n",
-                    exprOpText(value->op), longText(keyi->name));
+                    exprOpText(value->op), LongKeyNameText(keyi->name));
         }
     }
     else if (istreq(field, "locking") ||
@@ -1094,7 +1085,7 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
         log_err(info->keymap->ctx,
                 "Radio groups not supported; "
                 "Ignoring radio group specification for key %s\n",
-                longText(keyi->name));
+                LongKeyNameText(keyi->name));
         return false;
     }
     else if (istreq_prefix("overlay", field) ||
@@ -1102,7 +1093,7 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
         log_err(info->keymap->ctx,
                 "Overlays not supported; "
                 "Ignoring overlay specification for key %s\n",
-                longText(keyi->name));
+                LongKeyNameText(keyi->name));
     }
     else if (istreq(field, "repeating") ||
              istreq(field, "repeats") ||
@@ -1114,7 +1105,7 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
             log_err(info->keymap->ctx,
                     "Illegal repeat setting for %s; "
                     "Non-boolean repeat setting ignored\n",
-                    longText(keyi->name));
+                    LongKeyNameText(keyi->name));
             return false;
         }
         keyi->repeat = val;
@@ -1128,7 +1119,7 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
             log_err(info->keymap->ctx,
                     "Illegal groupsWrap setting for %s; "
                     "Non-boolean value ignored\n",
-                    longText(keyi->name));
+                    LongKeyNameText(keyi->name));
             return false;
         }
 
@@ -1147,7 +1138,7 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
             log_err(info->keymap->ctx,
                     "Illegal groupsClamp setting for %s; "
                     "Non-boolean value ignored\n",
-                    longText(keyi->name));
+                    LongKeyNameText(keyi->name));
             return false;
         }
 
@@ -1166,7 +1157,7 @@ SetSymbolsField(SymbolsInfo *info, KeyInfo *keyi, const char *field,
             log_err(info->keymap->ctx,
                     "Illegal group index for redirect of key %s; "
                     "Definition with non-integer group ignored\n",
-                    longText(keyi->name));
+                    LongKeyNameText(keyi->name));
             return false;
         }
 
@@ -1310,12 +1301,10 @@ SetExplicitGroup(SymbolsInfo *info, KeyInfo *keyi)
     if ((keyi->typesDefined | keyi->symsDefined | keyi->actsDefined) & ~1) {
         xkb_group_index_t i;
         log_warn(info->keymap->ctx,
-                 "For the map %s an explicit group specified\n",
-                 info->name);
-        log_warn(info->keymap->ctx,
+                 "For the map %s an explicit group specified, "
                  "but key %s has more than one group defined; "
                  "All groups except first one will be ignored\n",
-                 longText(keyi->name));
+                 info->name, LongKeyNameText(keyi->name));
         for (i = 1; i < XkbNumKbdGroups; i++) {
             keyi->numLevels[i] = 0;
             darray_free(keyi->syms[i]);
@@ -1738,7 +1727,7 @@ CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi,
         if (start_from == 0)
             log_lvl(info->keymap->ctx, 5,
                     "Key %s not found in keycodes; Symbols ignored\n",
-                    longText(keyi->name));
+                    LongKeyNameText(keyi->name));
         return false;
     }
     kc = XkbKeyGetKeycode(keymap, key);
@@ -1766,7 +1755,7 @@ CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi,
                         "Using %s for the %s key (keycode %d)\n",
                         keyi->numLevels[i],
                         xkb_atom_text(keymap->ctx, keyi->types[i]),
-                        longText(keyi->name), kc);
+                        LongKeyNameText(keyi->name), kc);
         }
         if (FindNamedType(keymap, keyi->types[i], &types[i])) {
             if (!autoType || keyi->numLevels[i] > 2)
@@ -1777,7 +1766,7 @@ CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi,
                     "Type \"%s\" is not defined; "
                     "Using TWO_LEVEL for the %s key (keycode %d)\n",
                     xkb_atom_text(keymap->ctx, keyi->types[i]),
-                    longText(keyi->name), kc);
+                    LongKeyNameText(keyi->name), kc);
             types[i] = XkbTwoLevelIndex;
         }
 
@@ -1788,7 +1777,7 @@ CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi,
                     "Type \"%s\" has %d levels, but %s has %d symbols; "
                     "Ignoring extra symbols\n",
                     type->name, type->num_levels,
-                    longText(keyi->name),
+                    LongKeyNameText(keyi->name),
                     keyi->numLevels[i]);
             keyi->numLevels[i] = type->num_levels;
         }
@@ -1806,7 +1795,7 @@ CopySymbolsDef(SymbolsInfo *info, KeyInfo *keyi,
         if (outActs == NULL) {
             log_wsgo(info->keymap->ctx,
                      "Could not enlarge actions for %s (key %d)\n",
-                     longText(keyi->name), kc);
+                     LongKeyNameText(keyi->name), kc);
             return false;
         }
         key->explicit |= XkbExplicitInterpretMask;
@@ -1897,7 +1886,7 @@ CopyModMapDef(SymbolsInfo *info, ModMapEntry *entry)
             log_lvl(info->keymap->ctx, 5,
                     "Key %s not found in keycodes; "
                     "Modifier map entry for %s not updated\n",
-                    longText(entry->u.keyName),
+                    LongKeyNameText(entry->u.keyName),
                     ModIndexText(entry->modifier));
             return false;
         }
@@ -1974,8 +1963,9 @@ CompileSymbols(XkbFile *file, struct xkb_keymap *keymap,
 
             if (key->num_groups < 1)
                 log_warn(info.keymap->ctx,
-                         "No symbols defined for <%.4s> (keycode %d)\n",
-                         key->name, XkbKeyGetKeycode(keymap, key));
+                         "No symbols defined for %s (keycode %d)\n",
+                         KeyNameText(key->name),
+                         XkbKeyGetKeycode(keymap, key));
         }
     }
 
diff --git a/src/xkbcomp/xkbcomp-priv.h b/src/xkbcomp/xkbcomp-priv.h
index 060c686..2af7223 100644
--- a/src/xkbcomp/xkbcomp-priv.h
+++ b/src/xkbcomp/xkbcomp-priv.h
@@ -53,7 +53,7 @@ const char *
 StmtTypeToString(enum stmt_type type);
 
 static inline unsigned long
-KeyNameToLong(const char *name)
+KeyNameToLong(const char name[XkbKeyNameLength])
 {
     return
         (((unsigned long)name[0]) << 24) |
@@ -63,7 +63,7 @@ KeyNameToLong(const char *name)
 }
 
 static inline void
-LongToKeyName(unsigned long val, char *name)
+LongToKeyName(unsigned long val, char name[XkbKeyNameLength])
 {
     name[0] = ((val >> 24) & 0xff);
     name[1] = ((val >> 16) & 0xff);
@@ -71,6 +71,14 @@ LongToKeyName(unsigned long val, char *name)
     name[3] = ((val >> 0) & 0xff);
 }
 
+static inline const char *
+LongKeyNameText(unsigned long val)
+{
+    char buf[XkbKeyNameLength];
+    LongToKeyName(val, buf);
+    return KeyNameText(buf);
+}
+
 static inline bool
 ReportNotArray(struct xkb_keymap *keymap, const char *type, const char *field,
                const char *name)
diff --git a/src/xkbcomp/xkbcomp.h b/src/xkbcomp/xkbcomp.h
index a153147..6774c7a 100644
--- a/src/xkbcomp/xkbcomp.h
+++ b/src/xkbcomp/xkbcomp.h
@@ -130,7 +130,7 @@ typedef struct _Expr {
         xkb_atom_t str;
         unsigned uval;
         int ival;
-        char keyName[5];
+        char keyName[XkbKeyNameLength];
     } value;
 } ExprDef;
 
@@ -151,15 +151,15 @@ typedef struct _VModDef {
 typedef struct _KeycodeDef {
     ParseCommon common;
     enum merge_mode merge;
-    char name[5];
+    char name[XkbKeyNameLength];
     unsigned long value;
 } KeycodeDef;
 
 typedef struct _KeyAliasDef {
     ParseCommon common;
     enum merge_mode merge;
-    char alias[5];
-    char real[5];
+    char alias[XkbKeyNameLength];
+    char real[XkbKeyNameLength];
 } KeyAliasDef;
 
 typedef struct _KeyTypeDef {
@@ -172,7 +172,7 @@ typedef struct _KeyTypeDef {
 typedef struct _SymbolsDef {
     ParseCommon common;
     enum merge_mode merge;
-    char keyName[5];
+    char keyName[XkbKeyNameLength];
     ExprDef *symbols;
 } SymbolsDef;