Skip to content

Commit e189226

Browse files
committed
clang-tidy: Miscellaneous fixes
1 parent 5cfd36a commit e189226

17 files changed

+55
-27
lines changed

.clang-tidy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Checks:
1616
- performance-*
1717
- google-*
1818
- -google-readability-braces-around-statements
19+
- -google-readability-todo
1920
# - misc-*
2021
# - -misc-include-cleaner
2122
# ExtraArgs:
@@ -47,5 +48,6 @@ CheckOptions:
4748
llvm-else-after-return.WarnOnUnfixable: 'false'
4849
llvm-qualified-auto.AddConstToQualified: 'false'
4950
bugprone-suspicious-enum-usage.StrictMode: 'true'
51+
bugprone-signed-char-misuse.CharTypdefsToIgnore: 'int8_t'
5052
SystemHeaders: false
5153
...

bench/bench.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ predict(long long t1, long long t2, struct estimate *est)
127127
{
128128
const long long t = fit(t1, t2);
129129
est->elapsed = t;
130-
est->stdev = truncl(sqrtl((long double)sqr(t1 - t) + (long double)sqr(t2 - 2 * t)));
130+
est->stdev =
131+
llroundl(sqrtl((long double)sqr(t1 - t) + (long double)sqr(t2 - 2 * t)));
131132
}
132133

133134
#define high(t, prec) ((t) + (prec))

bench/keysym-case-mappings.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ main(void)
5555
functions[f].toLower(ks);
5656
functions[f].toUpper(ks);
5757
}
58+
/* Avoid dangling pointers
59+
* NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores) */
5860
iter = xkb_keysym_iterator_unref(iter);
5961
}
6062
bench_stop(&bench);

scripts/update-keysyms-names-handling.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,11 +175,11 @@ def get_keysyms(path: Path) -> dict[int, list[Keysym]]:
175175
{
176176
size_t sum = 0;
177177
for (size_t i = 0; key[i] != '\0'; i++)
178-
sum += T[i % $NS] * key[i];
178+
sum += (size_t) (T[i % $NS] * key[i]);
179179
return sum % $NG;
180180
}
181181
182-
static size_t
182+
static inline size_t
183183
keysym_name_perfect_hash(const char *key)
184184
{
185185
return (

src/ks_tables.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2916,11 +2916,11 @@ keysym_name_hash_f(const char *key, const char *T)
29162916
{
29172917
size_t sum = 0;
29182918
for (size_t i = 0; key[i] != '\0'; i++)
2919-
sum += T[i % 32] * key[i];
2919+
sum += (size_t) (T[i % 32] * key[i]);
29202920
return sum % 4857;
29212921
}
29222922

2923-
static size_t
2923+
static inline size_t
29242924
keysym_name_perfect_hash(const char *key)
29252925
{
29262926
return (

src/scanner-utils.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,8 +206,9 @@ scanner_hex(struct scanner *s, uint8_t *out)
206206
int i;
207207
for (i = 0, *out = 0; is_xdigit(scanner_peek(s)) && i < 2; i++) {
208208
const char c = scanner_next(s);
209-
const char offset = (c >= '0' && c <= '9' ? '0' :
210-
c >= 'a' && c <= 'f' ? 'a' - 10 : 'A' - 10);
209+
const char offset = (char) (c >= '0' && c <= '9' ? '0' :
210+
c >= 'a' && c <= 'f' ? 'a' - 10
211+
: 'A' - 10);
211212
*out = *out * 16 + c - offset;
212213
}
213214
return i > 0;

src/utf8.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ utf32_to_utf8(uint32_t unichar, char *buffer)
2222
int count, shift, length;
2323
uint8_t head;
2424

25+
/* NOLINTBEGIN(bugprone-branch-clone) */
2526
if (unichar <= 0x007f) {
2627
buffer[0] = (char) unichar;
2728
buffer[1] = '\0';
@@ -46,6 +47,7 @@ utf32_to_utf8(uint32_t unichar, char *buffer)
4647
else {
4748
goto ill_formed_code_unit_subsequence;
4849
}
50+
/* NOLINTEND(bugprone-branch-clone) */
4951

5052
for (count = length - 1, shift = 0; count > 0; count--, shift += 6)
5153
buffer[count] = (char)(0x80 | ((unichar >> shift) & 0x3f));
@@ -73,6 +75,7 @@ is_valid_utf8(const char *ss, size_t len)
7375
* We can optimize if needed. */
7476
while (i < len)
7577
{
78+
/* NOLINTBEGIN(bugprone-branch-clone) */
7679
if (s[i] <= 0x7F) {
7780
tail_bytes = 0;
7881
}
@@ -115,6 +118,7 @@ is_valid_utf8(const char *ss, size_t len)
115118
else {
116119
return false;
117120
}
121+
/* NOLINTEND(bugprone-branch-clone) */
118122

119123
i++;
120124

src/xkbcomp/keymap.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ FindInterpForKey(struct xkb_keymap *keymap, const struct xkb_key *key,
118118
struct xkb_sym_interpret const **previous_interp;
119119
darray_foreach(previous_interp, *interprets) {
120120
if (*previous_interp == interp) {
121+
/* Keep as a safeguard against refactoring
122+
* NOLINTNEXTLINE(clang-analyzer-deadcode.DeadStores) */
121123
found = false;
122124
log_warn(keymap->ctx, XKB_LOG_MESSAGE_NO_ID,
123125
"Repeated interpretation ignored for keysym "

src/xkbcomp/rules.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -496,14 +496,14 @@ extract_layout_index(const char *s, size_t max_len, xkb_layout_index_t *out)
496496
}
497497
/* Numeric index */
498498

499-
#define parse_layout_int_index(s, endptr, index, out) \
500-
char *endptr; \
501-
long index = strtol(&(s)[1], &endptr, 10); \
502-
if (index < 0 || endptr[0] != ']' || index > XKB_MAX_GROUPS) \
503-
return -1; \
504-
/* To zero-based index. */ \
505-
*(out) = (xkb_layout_index_t)index - 1; \
506-
return (int)(endptr - (s) + 1) /* == length "[index]" */
499+
#define parse_layout_int_index(s, endptr, index, out) \
500+
char *(endptr); \
501+
long (index) = strtol(&(s)[1], &(endptr), 10); \
502+
if ((index) < 0 || (endptr)[0] != ']' || (index) > XKB_MAX_GROUPS) \
503+
return -1; \
504+
/* To zero-based index. */ \
505+
*(out) = (xkb_layout_index_t)(index) - 1; \
506+
return (int)((endptr) - (s) + 1) /* == length "[index]" */
507507

508508
parse_layout_int_index(s, endptr, index, out);
509509
}
@@ -1135,9 +1135,9 @@ append_expanded_kccgst_value(struct matcher *m, struct scanner *s,
11351135
* Appending +bar to +foo -> +foo+bar
11361136
*/
11371137

1138-
ch = (darray_empty(expanded) ? '\0' : darray_item(expanded, 0));
1138+
ch = (char) (darray_empty(expanded) ? '\0' : darray_item(expanded, 0));
11391139
expanded_plus = is_merge_mode_prefix(ch);
1140-
ch = (darray_empty(*to) ? '\0' : darray_item(*to, 0));
1140+
ch = (char) (darray_empty(*to) ? '\0' : darray_item(*to, 0));
11411141
to_plus = is_merge_mode_prefix(ch);
11421142

11431143
if (expanded_plus || darray_empty(*to))

src/xkbcomp/scanner.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ number(struct scanner *s, int64_t *out, int *out_tok)
3535
else if (is_float) {
3636
/* The parser currently just ignores floats, so the cast is
3737
* fine - the value doesn't matter. */
38+
#ifdef __GNUC__
3839
#pragma GCC diagnostic push
3940
#pragma GCC diagnostic ignored "-Wbad-function-cast"
41+
#endif
4042
x = (long long int) strtold(start, &end);
43+
#ifdef __GNUC__
4144
#pragma GCC diagnostic pop
45+
#endif
4246
}
4347
else
4448
x = strtoll(start, &end, 10);

0 commit comments

Comments
 (0)