Fix sign-compare warnings 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
diff --git a/src/keymap.c b/src/keymap.c
index 7d991d5..0830cc1 100644
--- a/src/keymap.c
+++ b/src/keymap.c
@@ -110,10 +110,10 @@ get_keymap_format_ops(enum xkb_keymap_format format)
[XKB_KEYMAP_FORMAT_TEXT_V1] = &text_v1_keymap_format_ops,
};
- if ((int) format < 0 || (int) format >= ARRAY_SIZE(keymap_format_ops))
+ if ((int) format < 0 || (int) format >= (int) ARRAY_SIZE(keymap_format_ops))
return NULL;
- return keymap_format_ops[format];
+ return keymap_format_ops[(int) format];
}
XKB_EXPORT struct xkb_keymap *
diff --git a/src/state.c b/src/state.c
index 3f470b1..3298592 100644
--- a/src/state.c
+++ b/src/state.c
@@ -121,9 +121,8 @@ get_entry_for_key_state(struct xkb_state *state, const struct xkb_key *key,
{
const struct xkb_key_type *type = key->groups[group].type;
xkb_mod_mask_t active_mods = state->components.mods & type->mods.mask;
- unsigned int i;
- for (i = 0; i < type->num_entries; i++) {
+ for (unsigned i = 0; i < type->num_entries; i++) {
/*
* If the virtual modifiers are not bound to anything, we're
* supposed to skip the entry (xserver does this with cached
@@ -170,7 +169,7 @@ wrap_group_into_range(int32_t group,
if (num_groups == 0)
return XKB_LAYOUT_INVALID;
- if (group < num_groups)
+ if (group >= 0 && (xkb_layout_index_t) group < num_groups)
return group;
switch (out_of_range_group_action) {
@@ -1042,11 +1041,11 @@ xkb_state_layout_index_is_active(struct xkb_state *state,
if (type & XKB_STATE_LAYOUT_EFFECTIVE)
ret |= (state->components.group == idx);
if (type & XKB_STATE_LAYOUT_DEPRESSED)
- ret |= (state->components.base_group == idx);
+ ret |= (state->components.base_group == (int32_t) idx);
if (type & XKB_STATE_LAYOUT_LATCHED)
- ret |= (state->components.latched_group == idx);
+ ret |= (state->components.latched_group == (int32_t) idx);
if (type & XKB_STATE_LAYOUT_LOCKED)
- ret |= (state->components.locked_group == idx);
+ ret |= (state->components.locked_group == (int32_t) idx);
return ret;
}
diff --git a/src/x11/keymap.c b/src/x11/keymap.c
index 0eedb30..9d680b1 100644
--- a/src/x11/keymap.c
+++ b/src/x11/keymap.c
@@ -354,7 +354,7 @@ get_types(struct xkb_keymap *keymap, xcb_connection_t *conn,
xcb_xkb_mod_def_iterator_t preserves_iter =
xcb_xkb_key_type_preserve_iterator(wire_type);
- FAIL_UNLESS(preserves_length <= type->num_entries);
+ FAIL_UNLESS((unsigned) preserves_length <= type->num_entries);
for (int j = 0; j < preserves_length; j++) {
xcb_xkb_mod_def_t *wire_preserve = preserves_iter.data;
@@ -405,7 +405,7 @@ get_sym_maps(struct xkb_keymap *keymap, xcb_connection_t *conn,
FAIL_UNLESS(key->num_groups <= ARRAY_SIZE(wire_sym_map->kt_index));
ALLOC_OR_FAIL(key->groups, key->num_groups);
- for (int j = 0; j < key->num_groups; j++) {
+ for (unsigned j = 0; j < key->num_groups; j++) {
FAIL_UNLESS(wire_sym_map->kt_index[j] < keymap->num_types);
key->groups[j].type = &keymap->types[wire_sym_map->kt_index[j]];
@@ -427,7 +427,7 @@ get_sym_maps(struct xkb_keymap *keymap, xcb_connection_t *conn,
int syms_length = xcb_xkb_key_sym_map_syms_length(wire_sym_map);
xcb_keysym_t *syms_iter = xcb_xkb_key_sym_map_syms(wire_sym_map);
- FAIL_UNLESS(syms_length == wire_sym_map->width * key->num_groups);
+ FAIL_UNLESS((unsigned) syms_length == wire_sym_map->width * key->num_groups);
for (int j = 0; j < syms_length; j++) {
xcb_keysym_t wire_keysym = *syms_iter;
@@ -883,7 +883,7 @@ get_indicator_names(struct xkb_keymap *keymap, xcb_connection_t *conn,
{
xcb_atom_t *iter = xcb_xkb_get_names_value_list_indicator_names(list);
- FAIL_UNLESS(msb_pos(reply->indicators) <= darray_size(keymap->leds));
+ FAIL_UNLESS(msb_pos(reply->indicators) <= (int) darray_size(keymap->leds));
for (int i = 0; i < NUM_INDICATORS; i++) {
if (reply->indicators & (1 << i)) {
@@ -965,7 +965,7 @@ get_key_names(struct xkb_keymap *keymap, xcb_connection_t *conn,
FAIL_UNLESS(reply->minKeyCode == keymap->min_key_code);
FAIL_UNLESS(reply->maxKeyCode == keymap->max_key_code);
FAIL_UNLESS(reply->firstKey == keymap->min_key_code);
- FAIL_UNLESS(reply->firstKey + reply->nKeys - 1 == keymap->max_key_code);
+ FAIL_UNLESS(reply->firstKey + reply->nKeys - 1U == keymap->max_key_code);
for (int i = 0; i < length; i++) {
xcb_xkb_key_name_t *wire = iter.data;
@@ -1105,7 +1105,7 @@ get_controls(struct xkb_keymap *keymap, xcb_connection_t *conn,
FAIL_UNLESS(keymap->max_key_code < XCB_XKB_CONST_PER_KEY_BIT_ARRAY_SIZE * 8);
- for (int i = keymap->min_key_code; i <= keymap->max_key_code; i++)
+ for (xkb_keycode_t i = keymap->min_key_code; i <= keymap->max_key_code; i++)
keymap->keys[i].repeats = !!(reply->perKeyRepeat[i / 8] & (1 << (i % 8)));
free(reply);
diff --git a/src/xkbcomp/action.c b/src/xkbcomp/action.c
index c13fc70..86acdf2 100644
--- a/src/xkbcomp/action.c
+++ b/src/xkbcomp/action.c
@@ -799,7 +799,7 @@ HandlePrivate(struct xkb_keymap *keymap, union xkb_action *action,
return false;
}
- if (ndx < 0 || ndx >= sizeof(act->data)) {
+ if (ndx < 0 || (size_t) ndx >= sizeof(act->data)) {
log_err(keymap->ctx,
"The data for a private action is %lu bytes long; "
"Attempt to use data[%d] ignored\n",
diff --git a/src/xkbcomp/keymap-dump.c b/src/xkbcomp/keymap-dump.c
index 6b4c266..0f5b958 100644
--- a/src/xkbcomp/keymap-dump.c
+++ b/src/xkbcomp/keymap-dump.c
@@ -92,7 +92,7 @@ check_write_buf(struct buf *buf, const char *fmt, ...)
if (printed < 0)
goto err;
- if (printed >= available)
+ if ((size_t) printed >= available)
if (!do_realloc(buf, printed))
goto err;
@@ -103,7 +103,7 @@ check_write_buf(struct buf *buf, const char *fmt, ...)
printed = vsnprintf(buf->buf + buf->size, available, fmt, args);
va_end(args);
- if (printed >= available || printed < 0)
+ if (printed < 0 || (size_t) printed >= available)
goto err;
buf->size += printed;
@@ -429,7 +429,7 @@ write_compat(struct xkb_keymap *keymap, struct buf *buf)
write_buf(buf, "\tinterpret.useModMapMods= AnyLevel;\n");
write_buf(buf, "\tinterpret.repeat= False;\n");
- for (int i = 0; i < keymap->num_sym_interprets; i++) {
+ for (unsigned i = 0; i < keymap->num_sym_interprets; i++) {
const struct xkb_sym_interpret *si = &keymap->sym_interprets[i];
write_buf(buf, "\tinterpret %s+%s(%s) {\n",
diff --git a/src/xkbcomp/keymap.c b/src/xkbcomp/keymap.c
index 549cf05..aee631f 100644
--- a/src/xkbcomp/keymap.c
+++ b/src/xkbcomp/keymap.c
@@ -92,7 +92,7 @@ FindInterpForKey(struct xkb_keymap *keymap, const struct xkb_key *key,
* sym_interprets array from the most specific to the least specific,
* such that when we find a match we return immediately.
*/
- for (int i = 0; i < keymap->num_sym_interprets; i++) {
+ for (unsigned i = 0; i < keymap->num_sym_interprets; i++) {
const struct xkb_sym_interpret *interp = &keymap->sym_interprets[i];
xkb_mod_mask_t mods;
diff --git a/test/atom.c b/test/atom.c
index a6794e0..bcb369a 100644
--- a/test/atom.c
+++ b/test/atom.c
@@ -47,7 +47,7 @@ random_string(char **str_out, size_t *len_out)
str = malloc(len + 1);
assert(str);
- for (int i = 0; i < len; i++)
+ for (size_t i = 0; i < len; i++)
str[i] = random_chars[rand() % ARRAY_SIZE(random_chars)];
/* Don't always terminate it; should work without. */
if (rand() % 2 == 0)
diff --git a/test/state.c b/test/state.c
index 74756fd..507ccfc 100644
--- a/test/state.c
+++ b/test/state.c
@@ -272,21 +272,21 @@ test_serialisation(struct xkb_keymap *keymap)
latched_mods = xkb_state_serialize_mods(state, XKB_STATE_MODS_LATCHED);
assert(latched_mods == 0);
locked_mods = xkb_state_serialize_mods(state, XKB_STATE_MODS_LOCKED);
- assert(locked_mods == (1 << caps));
+ assert(locked_mods == (1U << caps));
effective_mods = xkb_state_serialize_mods(state, XKB_STATE_MODS_EFFECTIVE);
assert(effective_mods == locked_mods);
xkb_state_update_key(state, KEY_LEFTSHIFT + EVDEV_OFFSET, XKB_KEY_DOWN);
base_mods = xkb_state_serialize_mods(state, XKB_STATE_MODS_DEPRESSED);
- assert(base_mods == (1 << shift));
+ assert(base_mods == (1U << shift));
latched_mods = xkb_state_serialize_mods(state, XKB_STATE_MODS_LATCHED);
assert(latched_mods == 0);
locked_mods = xkb_state_serialize_mods(state, XKB_STATE_MODS_LOCKED);
- assert(locked_mods == (1 << caps));
+ assert(locked_mods == (1U << caps));
effective_mods = xkb_state_serialize_mods(state, XKB_STATE_MODS_EFFECTIVE);
assert(effective_mods == (base_mods | locked_mods));
- base_mods |= (1 << ctrl);
+ base_mods |= (1U << ctrl);
xkb_state_update_mask(state, base_mods, latched_mods, locked_mods,
base_group, latched_group, locked_group);
@@ -328,10 +328,10 @@ test_consume(struct xkb_keymap *keymap)
print_state(state);
mask = xkb_state_serialize_mods(state, XKB_STATE_MODS_EFFECTIVE);
- assert(mask == ((1 << alt) | (1 << shift)));
+ assert(mask == ((1U << alt) | (1U << shift)));
mask = xkb_state_mod_mask_remove_consumed(state, KEY_EQUAL + EVDEV_OFFSET,
mask);
- assert(mask == (1 << alt));
+ assert(mask == (1U << alt));
xkb_state_unref(state);
}
@@ -339,7 +339,7 @@ test_consume(struct xkb_keymap *keymap)
static void
key_iter(struct xkb_keymap *keymap, xkb_keycode_t key, void *data)
{
- int *counter = (int *) data;
+ xkb_keycode_t *counter = data;
assert(*counter == key);
(*counter)++;
@@ -348,7 +348,7 @@ key_iter(struct xkb_keymap *keymap, xkb_keycode_t key, void *data)
static void
test_range(struct xkb_keymap *keymap)
{
- int counter;
+ xkb_keycode_t counter;
assert(xkb_keymap_min_keycode(keymap) == 9);
assert(xkb_keymap_max_keycode(keymap) == 253);