From 299c9762b1dbe53f3297c54e5526aeae767d1a10 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sun, 11 Dec 2022 10:24:13 -0800 Subject: Use unsigned ints when shifting to create bitmasks symbols.c:1057:28: portability: Shifting signed 32-bit value by 31 bits is implementation-defined behaviour. See condition at line 1049. [shiftTooManyBitsSigned] radio_groups |= (1 << (tmp.uval - 1)); ^ symbols.c:1049:41: note: Assuming that condition 'tmp.uval>32' is not redundant if ((tmp.uval < 1) || (tmp.uval > XkbMaxRadioGroups)) ^ symbols.c:1057:28: note: Shift radio_groups |= (1 << (tmp.uval - 1)); ^ symbols.c:1057:28: warning: Either the condition 'tmp.uval>32' is redundant or there is signed integer overflow for expression '1<<(tmp.uval-1)'. [integerOverflowCond] radio_groups |= (1 << (tmp.uval - 1)); ^ symbols.c:1049:41: note: Assuming that condition 'tmp.uval>32' is not redundant if ((tmp.uval < 1) || (tmp.uval > XkbMaxRadioGroups)) ^ symbols.c:1057:28: note: Integer overflow radio_groups |= (1 << (tmp.uval - 1)); ^ Signed-off-by: Alan Coopersmith --- expr.c | 2 +- keycodes.c | 4 ++-- keymap.c | 6 +++--- symbols.c | 52 ++++++++++++++++++++++++++-------------------------- vmod.c | 8 ++++---- 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/expr.c b/expr.c index 56e3988..4ca9820 100644 --- a/expr.c +++ b/expr.c @@ -273,7 +273,7 @@ LookupModMask(XPointer priv, else if (uStrCaseCmp(str, "none") == 0) val_rtrn->uval = 0; else if (LookupModIndex(priv, elem, field, type, val_rtrn)) - val_rtrn->uval = (1 << val_rtrn->uval); + val_rtrn->uval = (1U << val_rtrn->uval); else if (priv != NULL) { LookupPriv *lpriv = (LookupPriv *) priv; diff --git a/keycodes.c b/keycodes.c index 8e4fe9e..8e431c6 100644 --- a/keycodes.c +++ b/keycodes.c @@ -880,8 +880,8 @@ CompileKeycodes(XkbFile * file, XkbFileInfo * result, unsigned merge) XkbAtomGetString(NULL, ii->name), False); if (xkb->indicators != NULL) { - unsigned bit; - bit = 1 << (ii->ndx - 1); + unsigned bit = 1U << (ii->ndx - 1); + if (ii->virtual) xkb->indicators->phys_indicators &= ~bit; else diff --git a/keymap.c b/keymap.c index 06d1809..1640566 100644 --- a/keymap.c +++ b/keymap.c @@ -85,7 +85,7 @@ CompileKeymap(XkbFile * file, XkbFileInfo * result, unsigned merge) while ((file) && (ok)) { file->topName = mainName; - if ((have & (1 << file->type)) != 0) + if ((have & (1U << file->type)) != 0) { ERROR("More than one %s section in a %s file\n", XkbConfigText(file->type, XkbMessage), @@ -93,7 +93,7 @@ CompileKeymap(XkbFile * file, XkbFileInfo * result, unsigned merge) ACTION("All sections after the first ignored\n"); ok = False; } - else if ((1 << file->type) & (~legal)) + else if ((1U << file->type) & (~legal)) { ERROR("Cannot define %s in a %s file\n", XkbConfigText(file->type, XkbMessage), @@ -138,7 +138,7 @@ CompileKeymap(XkbFile * file, XkbFileInfo * result, unsigned merge) break; } if (ok) - have |= (1 << file->type); + have |= (1U << file->type); file = (XkbFile *) file->common.next; } /* compile the sections we have in the file one-by-one, or fail. */ diff --git a/symbols.c b/symbols.c index d5c2af4..ab11756 100644 --- a/symbols.c +++ b/symbols.c @@ -451,10 +451,10 @@ MergeKeyGroups(SymbolsInfo * info, from->syms[group] = NULL; into->acts[group] = resultActs; from->acts[group] = NULL; - into->symsDefined |= (1 << group); - from->symsDefined &= ~(1 << group); - into->actsDefined |= (1 << group); - from->actsDefined &= ~(1 << group); + into->symsDefined |= (1U << group); + from->symsDefined &= ~(1U << group); + into->actsDefined |= (1U << group); + from->actsDefined &= ~(1U << group); return True; } @@ -490,11 +490,11 @@ MergeKeys(SymbolsInfo * info, KeyInfo * into, KeyInfo * from) into->numLevels[i] = from->numLevels[i]; into->syms[i] = from->syms[i]; into->acts[i] = from->acts[i]; - into->symsDefined |= (1 << i); + into->symsDefined |= (1U << i); from->syms[i] = NULL; from->acts[i] = NULL; from->numLevels[i] = 0; - from->symsDefined &= ~(1 << i); + from->symsDefined &= ~(1U << i); if (into->syms[i]) into->defs.defined |= _Key_Syms; if (into->acts[i]) @@ -876,7 +876,7 @@ GetGroupIndex(KeyInfo * key, for (int i = 0; i < XkbNumKbdGroups; i++) { - if ((defined & (1 << i)) == 0) + if ((defined & (1U << i)) == 0) { *ndx_rtrn = i; return True; @@ -918,7 +918,7 @@ AddSymbolsToKey(KeyInfo * key, return False; if (value == NULL) { - key->symsDefined |= (1 << ndx); + key->symsDefined |= (1U << ndx); return True; } if (value->op != ExprKeysymList) @@ -944,7 +944,7 @@ AddSymbolsToKey(KeyInfo * key, ACTION("Symbols lost\n"); return False; } - key->symsDefined |= (1 << ndx); + key->symsDefined |= (1U << ndx); for (int i = 0; i < nSyms; i++) { if (!LookupKeysym(value->value.list.syms[i], &key->syms[ndx][i])) { if (warningLevel > 0) @@ -978,7 +978,7 @@ AddActionsToKey(KeyInfo * key, if (value == NULL) { - key->actsDefined |= (1 << ndx); + key->actsDefined |= (1U << ndx); return True; } if (value->op != ExprActionList) @@ -1011,7 +1011,7 @@ AddActionsToKey(KeyInfo * key, ACTION("Actions lost\n"); return False; } - key->actsDefined |= (1 << ndx); + key->actsDefined |= (1U << ndx); toAct = (XkbAnyAction *) key->acts[ndx]; act = value->value.child; @@ -1054,7 +1054,7 @@ SetAllowNone(KeyInfo * key, ExprDef * arrayNdx, ExprDef * value) tmp.uval); return False; } - radio_groups |= (1 << (tmp.uval - 1)); + radio_groups |= (1U << (tmp.uval - 1)); } if (!ExprResolveBoolean(value, &tmp, NULL, NULL)) { @@ -1140,7 +1140,7 @@ SetSymbolsField(KeyInfo * key, else { key->types[ndx.uval - 1] = XkbInternAtom(NULL, tmp.str, False); - key->typesDefined |= (1 << (ndx.uval - 1)); + key->typesDefined |= (1U << (ndx.uval - 1)); } } else if (uStrCaseCmp(field, "symbols") == 0) @@ -1206,7 +1206,7 @@ SetSymbolsField(KeyInfo * key, key->behavior.type = XkbKB_RadioGroup | (permanent ? XkbKB_Permanent : 0); key->behavior.data = tmp.uval - 1; - if (key->allowNone & (1 << (tmp.uval - 1))) + if (key->allowNone & (1U << (tmp.uval - 1))) key->behavior.data |= XkbKB_RGAllowNone; key->defs.defined |= _Key_Behavior; } @@ -1532,7 +1532,7 @@ SetExplicitGroup(SymbolsInfo * info, KeyInfo * key) key->types[i] = (Atom) 0; } } - key->typesDefined = key->symsDefined = key->actsDefined = 1 << group; + key->typesDefined = key->symsDefined = key->actsDefined = 1U << group; key->numLevels[group] = key->numLevels[0]; key->numLevels[0] = 0; @@ -1831,7 +1831,7 @@ PrepareKeyDef(KeyInfo * key) /* get highest group number */ for (i = XkbNumKbdGroups - 1; i >= 0; i--) { - if (defined & (1 << i)) + if (defined & (1U << i)) break; } lastGroup = i; @@ -1846,7 +1846,7 @@ PrepareKeyDef(KeyInfo * key) { int width; - if (defined & (1 << i)) + if (defined & (1U << i)) continue; width = key->numLevels[0]; if (key->typesDefined & 1) @@ -1855,7 +1855,7 @@ PrepareKeyDef(KeyInfo * key) { key->types[i] = key->types[0]; } - key->typesDefined |= 1 << i; + key->typesDefined |= 1U << i; } if ((key->actsDefined & 1) && key->acts[0]) { @@ -1863,7 +1863,7 @@ PrepareKeyDef(KeyInfo * key) if (key->acts[i] == NULL) continue; memcpy(key->acts[i], key->acts[0], width * sizeof(XkbAction)); - key->actsDefined |= 1 << i; + key->actsDefined |= 1U << i; } if ((key->symsDefined & 1) && key->syms[0]) { @@ -1871,7 +1871,7 @@ PrepareKeyDef(KeyInfo * key) if (key->syms[i] == NULL) continue; memcpy(key->syms[i], key->syms[0], width * sizeof(KeySym)); - key->symsDefined |= 1 << i; + key->symsDefined |= 1U << i; } if (defined & 1) { @@ -1962,8 +1962,8 @@ CopySymbolsDef(XkbFileInfo * result, KeyInfo * key, int start_from) for (i = width = nGroups = 0; i < XkbNumKbdGroups; i++) { if (((i + 1) > nGroups) - && (((key->symsDefined | key->actsDefined) & (1 << i)) - || (key->typesDefined) & (1 << i))) + && (((key->symsDefined | key->actsDefined) & (1U << i)) + || (key->typesDefined) & (1U << i))) nGroups = i + 1; if (key->acts[i]) haveActions = True; @@ -1993,7 +1993,7 @@ CopySymbolsDef(XkbFileInfo * result, KeyInfo * key, int start_from) if (FindNamedType(xkb, key->types[i], &types[i])) { if (!autoType || key->numLevels[i] > 2) - xkb->server->explicit[kc] |= (1 << i); + xkb->server->explicit[kc] |= (1U << i); } else { @@ -2128,9 +2128,9 @@ CopySymbolsDef(XkbFileInfo * result, KeyInfo * key, int start_from) if (key->repeat != RepeatUndefined) { if (key->repeat == RepeatYes) - xkb->ctrls->per_key_repeat[kc / 8] |= (1 << (kc % 8)); + xkb->ctrls->per_key_repeat[kc / 8] |= (1U << (kc % 8)); else - xkb->ctrls->per_key_repeat[kc / 8] &= ~(1 << (kc % 8)); + xkb->ctrls->per_key_repeat[kc / 8] &= ~(1U << (kc % 8)); xkb->server->explicit[kc] |= XkbExplicitAutoRepeatMask; } @@ -2174,7 +2174,7 @@ CopyModMapDef(XkbFileInfo * result, ModMapEntry * entry) } return False; } - xkb->map->modmap[kc] |= (1 << entry->modifier); + xkb->map->modmap[kc] |= (1U << entry->modifier); return True; } diff --git a/vmod.c b/vmod.c index 17aa7a7..4e591cd 100644 --- a/vmod.c +++ b/vmod.c @@ -137,9 +137,9 @@ HandleVModDef(VModDef * stmt, unsigned mergeMode, VModInfo * info) ACTION("Exiting\n"); return False; } - info->defined |= (1 << nextFree); - info->newlyDefined |= (1 << nextFree); - info->available |= (1 << nextFree); + info->defined |= (1U << nextFree); + info->newlyDefined |= (1U << nextFree); + info->available |= (1U << nextFree); names->vmods[nextFree] = stmtName; if (stmt->value == NULL) return True; @@ -217,7 +217,7 @@ LookupVModMask(XPointer priv, if (LookupVModIndex(priv, elem, field, type, val_rtrn)) { unsigned ndx = val_rtrn->uval; - val_rtrn->uval = (1 << (XkbNumModifiers + ndx)); + val_rtrn->uval = (1U << (XkbNumModifiers + ndx)); return True; } return False; -- cgit v1.2.3