Commit 2165e16ed925616f2e3760ae9b41a8a076b22f5e

Ran Benita 2012-03-24T02:36:11

Fix all -Wsign-compare warnings i.e comparison of signed and unsigned values. These are mostly harmless but fixing them allows to compile cleanly with -Wextra. 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
diff --git a/src/alloc.c b/src/alloc.c
index 3b4e33a..66e2b76 100644
--- a/src/alloc.c
+++ b/src/alloc.c
@@ -99,7 +99,7 @@ XkbcFreeCompatMap(struct xkb_desc * xkb)
 }
 
 int
-XkbcAllocNames(struct xkb_desc * xkb, unsigned which, int nTotalAliases)
+XkbcAllocNames(struct xkb_desc * xkb, unsigned which, unsigned nTotalAliases)
 {
     struct xkb_names * names;
 
diff --git a/src/malloc.c b/src/malloc.c
index 3818cdd..6168a67 100644
--- a/src/malloc.c
+++ b/src/malloc.c
@@ -121,7 +121,7 @@ XkbcAllocClientMap(struct xkb_desc * xkb, unsigned which, unsigned nTotalTypes)
 int
 XkbcAllocServerMap(struct xkb_desc * xkb, unsigned which, unsigned nNewActions)
 {
-    int i;
+    unsigned i;
     struct xkb_server_map * map;
 
     if (!xkb)
@@ -166,7 +166,7 @@ XkbcAllocServerMap(struct xkb_desc * xkb, unsigned which, unsigned nNewActions)
             map->num_acts = 1;
             map->size_acts = nNewActions + 1;
         }
-        else if ((map->size_acts - map->num_acts) < nNewActions) {
+        else if ((map->size_acts - map->num_acts) < (int)nNewActions) {
             unsigned need;
             union xkb_action *prev_acts = map->acts;
 
@@ -298,7 +298,7 @@ XkbcResizeKeySyms(struct xkb_desc * xkb, xkb_keycode_t key,
     newSyms[0] = NoSymbol;
     nSyms = 1;
     for (i = xkb->min_key_code; i <= xkb->max_key_code; i++) {
-        int nCopy;
+        uint32_t nCopy;
 
         nCopy = nKeySyms = XkbKeyNumSyms(xkb, i);
         if ((nKeySyms == 0) && (i != key))
@@ -325,7 +325,7 @@ XkbcResizeKeySyms(struct xkb_desc * xkb, xkb_keycode_t key,
 }
 
 union xkb_action *
-XkbcResizeKeyActions(struct xkb_desc * xkb, xkb_keycode_t key, int needed)
+XkbcResizeKeyActions(struct xkb_desc * xkb, xkb_keycode_t key, uint32_t needed)
 {
     xkb_keycode_t i, nActs;
     union xkb_action *newActs;
@@ -336,10 +336,10 @@ XkbcResizeKeyActions(struct xkb_desc * xkb, xkb_keycode_t key, int needed)
     }
 
     if (XkbKeyHasActions(xkb, key) &&
-        (XkbKeyNumSyms(xkb, key) >= (unsigned)needed))
+        (XkbKeyNumSyms(xkb, key) >= (int)needed))
         return XkbKeyActionsPtr(xkb, key);
 
-    if (xkb->server->size_acts - xkb->server->num_acts >= (unsigned)needed) {
+    if (xkb->server->size_acts - xkb->server->num_acts >= (int)needed) {
         xkb->server->key_acts[key] = xkb->server->num_acts;
         xkb->server->num_acts += needed;
 
diff --git a/src/map.c b/src/map.c
index ece711f..34df22b 100644
--- a/src/map.c
+++ b/src/map.c
@@ -275,7 +275,7 @@ xkb_key_get_group(struct xkb_state *state, xkb_keycode_t key)
 {
     unsigned int info = XkbKeyGroupInfo(state->xkb, key);
     unsigned int num_groups = XkbKeyNumGroups(state->xkb, key);
-    int ret = state->group;
+    unsigned int ret = state->group;
 
     if (ret < XkbKeyNumGroups(state->xkb, key))
         return ret;
diff --git a/src/maprules.c b/src/maprules.c
index 80e2cb3..ecac8ae 100644
--- a/src/maprules.c
+++ b/src/maprules.c
@@ -263,7 +263,8 @@ SetUpRemap(InputLine *line,RemapSpec *remap)
    char *tok, *str;
    unsigned present, l_ndx_present, v_ndx_present;
    int i;
-   int len, ndx;
+   size_t len;
+   int ndx;
    _Xstrtokparams strtok_buf;
 #ifdef DEBUG
    Bool found;
@@ -727,7 +728,7 @@ static void
 XkbRF_CheckApplyRules(	XkbRF_RulesPtr 		rules,
 			XkbRF_MultiDefsPtr	mdefs,
 			struct xkb_component_names *	names,
-			int			flags)
+			unsigned int			flags)
 {
     int i;
     XkbRF_RulePtr rule;
@@ -751,7 +752,8 @@ static char *
 XkbRF_SubstituteVars(char *name, XkbRF_MultiDefsPtr mdefs)
 {
     char *str, *outstr, *orig, *var;
-    int len, ndx;
+    size_t len;
+    int ndx;
 
     orig= name;
     str= strchr(name,'%');
diff --git a/src/text.c b/src/text.c
index 1ed5f7d..d8f6481 100644
--- a/src/text.c
+++ b/src/text.c
@@ -36,7 +36,7 @@
 
 #define BUFFER_SIZE 1024
 static char textBuffer[BUFFER_SIZE];
-static int tbNext = 0;
+static unsigned int tbNext = 0;
 
 static char *
 tbGetBuffer(unsigned int size)
diff --git a/src/xkballoc.h b/src/xkballoc.h
index 9abecc6..2839eda 100644
--- a/src/xkballoc.h
+++ b/src/xkballoc.h
@@ -36,7 +36,7 @@ extern int
 XkbcAllocCompatMap(struct xkb_desc * xkb, unsigned which, unsigned nSI);
 
 extern int
-XkbcAllocNames(struct xkb_desc * xkb, unsigned which, int nTotalAliases);
+XkbcAllocNames(struct xkb_desc * xkb, unsigned which, unsigned nTotalAliases);
 
 extern int
 XkbcAllocControls(struct xkb_desc * xkb, unsigned which);
@@ -65,7 +65,7 @@ extern xkb_keysym_t *
 XkbcResizeKeySyms(struct xkb_desc * xkb, xkb_keycode_t key, uint32_t needed);
 
 extern union xkb_action *
-XkbcResizeKeyActions(struct xkb_desc * xkb, xkb_keycode_t key, int needed);
+XkbcResizeKeyActions(struct xkb_desc * xkb, xkb_keycode_t key, uint32_t needed);
 
 extern void
 XkbcFreeClientMap(struct xkb_desc * xkb);
diff --git a/src/xkbcomp/compat.c b/src/xkbcomp/compat.c
index 89e2023..31de1e4 100644
--- a/src/xkbcomp/compat.c
+++ b/src/xkbcomp/compat.c
@@ -102,7 +102,7 @@ siText(SymInterpInfo * si, CompatInfo * info)
 static void
 InitCompatInfo(CompatInfo * info, struct xkb_desc * xkb)
 {
-    int i;
+    unsigned int i;
 
     info->xkb = xkb;
     info->name = NULL;
@@ -132,7 +132,7 @@ InitCompatInfo(CompatInfo * info, struct xkb_desc * xkb)
 static void
 ClearCompatInfo(CompatInfo * info, struct xkb_desc * xkb)
 {
-    int i;
+    unsigned int i;
     ActionInfo *next;
 
     free(info->name);
diff --git a/src/xkbcomp/keycodes.c b/src/xkbcomp/keycodes.c
index 6a05dc2..f03d7dd 100644
--- a/src/xkbcomp/keycodes.c
+++ b/src/xkbcomp/keycodes.c
@@ -351,7 +351,7 @@ InitKeyNamesInfo(KeyNamesInfo * info)
 static int
 FindKeyByLong(KeyNamesInfo * info, unsigned long name)
 {
-    int i;
+    uint64_t i;
 
     for (i = info->computedMin; i <= info->computedMax; i++)
     {
@@ -371,7 +371,7 @@ AddKeyName(KeyNamesInfo * info,
            xkb_keycode_t kc,
            char *name, unsigned merge, unsigned fileID, Bool reportCollisions)
 {
-    int old;
+    xkb_keycode_t old;
     unsigned long lval;
 
     if (kc > info->arraySize && !ResizeKeyNameArrays(info, kc)) {
@@ -474,7 +474,7 @@ static void
 MergeIncludedKeycodes(KeyNamesInfo * into, KeyNamesInfo * from,
                       unsigned merge)
 {
-    int i;
+    uint64_t i;
     char buf[5];
 
     if (from->errorCount > 0)
@@ -549,9 +549,11 @@ HandleIncludeKeycodes(IncludeStmt * stmt, struct xkb_desc * xkb, KeyNamesInfo * 
 {
     unsigned newMerge;
     XkbFile *rtrn;
-    KeyNamesInfo included = {NULL};
+    KeyNamesInfo included;
     Bool haveSelf;
 
+    memset(&included, 0, sizeof(included));
+
     haveSelf = False;
     if ((stmt->file == NULL) && (stmt->map == NULL))
     {
@@ -894,7 +896,7 @@ CompileKeycodes(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
         if (XkbcAllocNames(xkb, XkbKeyNamesMask | XkbIndicatorNamesMask, 0)
                 == Success)
         {
-            int i;
+            uint64_t i;
             for (i = info.computedMin; i <= info.computedMax; i++)
                 LongToKeyName(info.names[i], xkb->names->keys[i].name);
         }
diff --git a/src/xkbcomp/keytypes.c b/src/xkbcomp/keytypes.c
index 0d6a1f2..00dc139 100644
--- a/src/xkbcomp/keytypes.c
+++ b/src/xkbcomp/keytypes.c
@@ -57,12 +57,12 @@ typedef struct _KeyTypeInfo
     unsigned mask;
     unsigned vmask;
     Bool groupInfo;
-    int numLevels;
-    int nEntries;
-    int szEntries;
+    unsigned numLevels;
+    unsigned nEntries;
+    unsigned szEntries;
     struct xkb_kt_map_entry * entries;
     PreserveInfo *preserve;
-    int szNames;
+    unsigned szNames;
     xkb_atom_t *lvlNames;
 } KeyTypeInfo;
 
@@ -72,7 +72,7 @@ typedef struct _KeyTypesInfo
     int errorCount;
     int fileID;
     unsigned stdPresent;
-    int nTypes;
+    unsigned nTypes;
     KeyTypeInfo *types;
     KeyTypeInfo dflt;
     VModInfo vmods;
@@ -445,7 +445,7 @@ HandleIncludeKeyTypes(IncludeStmt * stmt,
 static struct xkb_kt_map_entry *
 FindMatchingMapEntry(KeyTypeInfo * type, unsigned mask, unsigned vmask)
 {
-    int i;
+    unsigned int i;
     struct xkb_kt_map_entry * entry;
 
     for (i = 0, entry = type->entries; i < type->nEntries; i++, entry++)
@@ -459,7 +459,7 @@ FindMatchingMapEntry(KeyTypeInfo * type, unsigned mask, unsigned vmask)
 static void
 DeleteLevel1MapEntries(KeyTypeInfo * type)
 {
-    int i, n;
+    unsigned int i, n;
 
     for (i = 0; i < type->nEntries; i++)
     {
@@ -929,7 +929,7 @@ static int
 HandleKeyTypeDef(KeyTypeDef * def,
                  struct xkb_desc * xkb, unsigned merge, KeyTypesInfo * info)
 {
-    int i;
+    unsigned int i;
     KeyTypeInfo type;
 
     if (def->merge != MergeDefault)
@@ -1070,7 +1070,7 @@ HandleKeyTypesFile(XkbFile * file,
 static Bool
 CopyDefToKeyType(struct xkb_desc * xkb, struct xkb_key_type * type, KeyTypeInfo * def)
 {
-    int i;
+    unsigned int i;
     PreserveInfo *pre;
 
     for (pre = def->preserve; pre != NULL;
@@ -1151,7 +1151,7 @@ CompileKeyTypes(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
 
     if (info.errorCount == 0)
     {
-        int i;
+        unsigned int i;
         KeyTypeInfo *def;
         struct xkb_key_type *type, *next;
 
diff --git a/src/xkbcomp/misc.c b/src/xkbcomp/misc.c
index d141a80..dd480f1 100644
--- a/src/xkbcomp/misc.c
+++ b/src/xkbcomp/misc.c
@@ -250,7 +250,7 @@ Bool
 FindNamedKey(struct xkb_desc * xkb,
              unsigned long name,
              xkb_keycode_t *kc_rtrn,
-             Bool use_aliases, Bool create, int start_from)
+             Bool use_aliases, Bool create, xkb_keycode_t start_from)
 {
     unsigned n;
 
@@ -318,7 +318,7 @@ Bool
 FindKeyNameForAlias(struct xkb_desc * xkb, unsigned long lname,
                     unsigned long *real_name)
 {
-    int i;
+    unsigned int i;
     char name[XkbKeyNameLength + 1];
 
     if (xkb && xkb->names && xkb->names->key_aliases)
diff --git a/src/xkbcomp/misc.h b/src/xkbcomp/misc.h
index cdeb1f2..197721f 100644
--- a/src/xkbcomp/misc.h
+++ b/src/xkbcomp/misc.h
@@ -80,7 +80,7 @@ extern Bool FindNamedKey(struct xkb_desc * /* xkb */ ,
                          xkb_keycode_t * /* kc_rtrn */ ,
                          Bool /* use_aliases */ ,
                          Bool /* create */ ,
-                         int    /* start_from */
+                         xkb_keycode_t    /* start_from */
     );
 
 extern Bool FindKeyNameForAlias(struct xkb_desc * /* xkb */ ,
diff --git a/src/xkbcomp/symbols.c b/src/xkbcomp/symbols.c
index 188d649..35210e8 100644
--- a/src/xkbcomp/symbols.c
+++ b/src/xkbcomp/symbols.c
@@ -63,7 +63,7 @@ typedef struct _KeyInfo
     unsigned char typesDefined;
     unsigned char symsDefined;
     unsigned char actsDefined;
-    short numLevels[XkbNumKbdGroups];
+    unsigned int numLevels[XkbNumKbdGroups];
     xkb_keysym_t *syms[XkbNumKbdGroups];
     union xkb_action *acts[XkbNumKbdGroups];
     xkb_atom_t types[XkbNumKbdGroups];
@@ -159,7 +159,7 @@ CopyKeyInfo(KeyInfo * old, KeyInfo * new, Bool clearOld)
     }
     else
     {
-        int width;
+        unsigned int width;
         for (i = 0; i < XkbNumKbdGroups; i++)
         {
             width = new->numLevels[i];
@@ -252,7 +252,7 @@ InitSymbolsInfo(SymbolsInfo * info, struct xkb_desc * xkb)
 static void
 FreeSymbolsInfo(SymbolsInfo * info)
 {
-    int i;
+    unsigned int i;
 
     free(info->name);
     if (info->keys)
@@ -308,8 +308,8 @@ MergeKeyGroups(SymbolsInfo * info,
 {
     xkb_keysym_t *resultSyms;
     union xkb_action *resultActs;
-    int resultWidth;
-    int i;
+    unsigned int resultWidth;
+    unsigned int i;
     Bool report, clobber;
 
     clobber = (from->defs.merge != MergeAugment);
@@ -576,7 +576,7 @@ MergeKeys(SymbolsInfo * info, KeyInfo * into, KeyInfo * from)
 static Bool
 AddKeySymbols(SymbolsInfo * info, KeyInfo * key, struct xkb_desc * xkb)
 {
-    int i;
+    unsigned int i;
     unsigned long real_name;
 
     for (i = 0; i < info->nKeys; i++)
@@ -688,7 +688,7 @@ static void
 MergeIncludedSymbols(SymbolsInfo * into, SymbolsInfo * from,
                      unsigned merge, struct xkb_desc * xkb)
 {
-    int i;
+    unsigned int i;
     KeyInfo *key;
 
     if (from->errorCount > 0)
@@ -887,7 +887,8 @@ AddSymbolsToKey(KeyInfo * key,
                 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
 {
     unsigned ndx, nSyms;
-    int i;
+    unsigned int i;
+    long j;
 
     if (!GetGroupIndex(key, arrayNdx, SYMBOLS, &ndx))
         return False;
@@ -928,8 +929,8 @@ AddSymbolsToKey(KeyInfo * key,
             key->syms[ndx][i] = NoSymbol;
         }
     }
-    for (i = key->numLevels[ndx] - 1;
-         (i >= 0) && (key->syms[ndx][i] == NoSymbol); i--)
+    for (j = key->numLevels[ndx] - 1;
+         (j >= 0) && (key->syms[ndx][j] == NoSymbol); j--)
     {
         key->numLevels[ndx]--;
     }
@@ -942,7 +943,7 @@ AddActionsToKey(KeyInfo * key,
                 char *field,
                 ExprDef * arrayNdx, ExprDef * value, SymbolsInfo * info)
 {
-    int i;
+    unsigned int i;
     unsigned ndx, nActs;
     ExprDef *act;
     struct xkb_any_action *toAct;
@@ -1738,7 +1739,7 @@ PrepareKeyDef(KeyInfo * key)
 static Bool
 CopySymbolsDef(struct xkb_desc * xkb, KeyInfo *key, int start_from)
 {
-    int i;
+    unsigned int i;
     xkb_keycode_t kc;
     unsigned width, tmp, nGroups;
     struct xkb_key_type * type;
@@ -1966,7 +1967,7 @@ CopyModMapDef(struct xkb_desc * xkb, ModMapEntry *entry)
 Bool
 CompileSymbols(XkbFile *file, struct xkb_desc * xkb, unsigned merge)
 {
-    int i;
+    unsigned int i;
     SymbolsInfo info;
 
     InitSymbolsInfo(&info, xkb);
diff --git a/src/xkbcomp/xkbcomp.h b/src/xkbcomp/xkbcomp.h
index a63564d..3c98a4e 100644
--- a/src/xkbcomp/xkbcomp.h
+++ b/src/xkbcomp/xkbcomp.h
@@ -246,7 +246,7 @@ typedef struct _IndicatorMapDef
 typedef struct _XkbFile
 {
     ParseCommon common;
-    int type;
+    unsigned type;
     char *topName;
     char *name;
     ParseCommon *defs;
diff --git a/src/xkbcomp/xkbpath.c b/src/xkbcomp/xkbpath.c
index 06dd71a..dfeab2f 100644
--- a/src/xkbcomp/xkbpath.c
+++ b/src/xkbcomp/xkbpath.c
@@ -44,9 +44,9 @@
 
 static Bool noDefaultPath = False;
 /* number of entries allocated for includePath */
-static int szPath;
+static size_t szPath;
 /* number of actual entries in includePath */
-static int nPathEntries;
+static size_t nPathEntries;
 /* Holds all directories we might be including data from */
 static char **includePath = NULL;
 
@@ -184,7 +184,7 @@ XkbInitIncludePath(void)
 static void
 XkbClearIncludePath(void)
 {
-    int i;
+    size_t i;
 
     if (szPath > 0)
     {
@@ -249,7 +249,7 @@ XkbAddDirectoryToPath(const char *dir)
     includePath[nPathEntries] = strdup(dir);
     if (includePath[nPathEntries] == NULL)
     {
-        WSGO("Allocation failed (includePath[%d])\n", nPathEntries);
+        WSGO("Allocation failed (includePath[%zd])\n", nPathEntries);
         return False;
     }
     nPathEntries++;
@@ -315,7 +315,8 @@ XkbDirectoryForInclude(unsigned type)
 FILE *
 XkbFindFileInPath(const char *name, unsigned type, char **pathRtrn)
 {
-    int i, ret;
+    size_t i;
+    int ret;
     FILE *file = NULL;
     char buf[PATH_MAX];
     const char *typeDir;
@@ -331,7 +332,7 @@ XkbFindFileInPath(const char *name, unsigned type, char **pathRtrn)
 
         ret = snprintf(buf, sizeof(buf), "%s/%s/%s",
                        includePath[i], typeDir, name);
-        if (ret >= sizeof(buf))
+        if (ret >= (ssize_t)sizeof(buf))
         {
             ERROR("File name (%s/%s/%s) too long\n", includePath[i],
                    typeDir, name);