summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2020-04-05 20:12:28 -0700
committerKaz Kylheku <kaz@kylheku.com>2020-04-05 20:12:28 -0700
commit49d82c3b34227ec0520eb1cf1bb22083453b49a7 (patch)
tree96e32c168fcd37be665cdbcb8bfb380d87ff08c2
parent998a47a585ae540f0f3229dcd68b3d04ac657c36 (diff)
downloadtxr-49d82c3b34227ec0520eb1cf1bb22083453b49a7.tar.gz
txr-49d82c3b34227ec0520eb1cf1bb22083453b49a7.tar.bz2
txr-49d82c3b34227ec0520eb1cf1bb22083453b49a7.zip
warning cleanup: suspicious switch fallthrough cases.
This is the seventh round of an effort to enable GCC's -Wextra option. Warnings about switch fallthrough situations are addressed. GCC now has a diagnostic for this that is enabled by -Wextra in such a way that if a fallthrough comment is present, the diagnostic is suppressed. In much of the code, we have such a comment. It's missing in a few places, or misplaced. There are also some real bugs. * hash.c (hash_buf): Add fallthrough comments to intentional fallthrough cases. (hash_hash_op): bugfix: add break statement. The 32 and 64 bit cases are independent (at compile time). * lib.c (cdr, nullify, list_collect, empty): Add fallthrough comment. (int_str): Add missing break. This has not caused a bug though because setting the octzero flag in the zerox case is harmless to the logic which follows. * linenoise.c (edit): Move misplaced fallthrough. * sysif.c (fcntl_wrap): Bugfix: add missing break, without which errno is tampered to hold EINVAL, in spite of a successful F_SETLK, F_SETLKW or F_GETLK operation. * unwind.h (jmp_restore): Declare noreturn, so that GCC does not issue a false positive warning about a fallthrough in uw_unwind_to_exit_point. * utf8.c (utf8_from_buf, utf8_decode): Move a fallthrough comment outside of preprocessing, so it is properly processed by GCC's diagnostic.
-rw-r--r--hash.c5
-rw-r--r--lib.c6
-rw-r--r--linenoise/linenoise.c2
-rw-r--r--sysif.c1
-rw-r--r--unwind.h2
-rw-r--r--utf8.c4
6 files changed, 16 insertions, 4 deletions
diff --git a/hash.c b/hash.c
index 9f4df00b..8a298de2 100644
--- a/hash.c
+++ b/hash.c
@@ -155,10 +155,13 @@ static u32_t hash_buf(const mem_t *ptr, ucnum size, u32_t seed, int *pcount)
switch (size) {
case 3:
in |= convert(u32_t, tail[2]) << 16;
+ /* fallthrough */
case 2:
in |= convert(u32_t, tail[1]) << 8;
+ /* fallthrough */
case 1:
in |= convert(u32_t, tail[0]);
+ break;
}
acc ^= in;
@@ -472,8 +475,10 @@ static ucnum hash_hash_op(val obj, int *count, ucnum seed)
switch (CHAR_BIT * sizeof (mem_t *)) {
case 32:
out += coerce(ucnum, h->hops) >> 4;
+ break;
case 64: default:
out += coerce(ucnum, h->hops) >> 5;
+ break;
}
out += equal_hash(h->userdata, count, seed);
diff --git a/lib.c b/lib.c
index c61cf60d..6fae0008 100644
--- a/lib.c
+++ b/lib.c
@@ -601,6 +601,7 @@ val cdr(val cons)
return funcall2(lambda_meth, cons, rcons(one, t));
}
}
+ /* fallthrough */
default:
type_mismatch(lit("cdr: ~s is not a cons"), cons, nao);
}
@@ -1061,6 +1062,7 @@ val nullify(val seq)
if (nullify_meth)
return funcall1(nullify_meth, seq);
}
+ /* fallthrough */
default:
return seq;
}
@@ -1107,6 +1109,7 @@ again:
replace_obj(tailobj, items, t, t);
return ptail;
}
+ /* fallthrough */
default:
uw_throwf(error_s, lit("cannot append ~s"), deref(ptail), nao);
}
@@ -4568,8 +4571,10 @@ val int_str(val str, val base)
case 'x': case 'X':
zerox = 1;
wcs += 2;
+ break;
default:
octzero = 1;
+ break;
}
break;
}
@@ -10415,6 +10420,7 @@ val empty(val seq)
return eq(funcall1(length_meth, seq), zero);
return if3(nullify_meth && funcall1(nullify_meth, seq), nil, seq);
}
+ /* fallthrough */
default:
type_mismatch(lit("empty: ~s is not a sequence"), seq, nao);
}
diff --git a/linenoise/linenoise.c b/linenoise/linenoise.c
index 75721075..5418aeda 100644
--- a/linenoise/linenoise.c
+++ b/linenoise/linenoise.c
@@ -2212,8 +2212,8 @@ static int edit(lino_t *l, const wchar_t *prompt)
}
break;
}
- /* fallthrough */
l->save_hist_idx = l->history_index;
+ /* fallthrough */
case CTL('F'):
ret = l->len;
if (l->mlmode)
diff --git a/sysif.c b/sysif.c
index dd563b7b..a3b3ff91 100644
--- a/sysif.c
+++ b/sysif.c
@@ -895,6 +895,7 @@ static val fcntl_wrap(val fd_in, val cmd_in, val arg_in)
if (cmd == F_GETLK)
flock_unpack(arg_in, &fl);
}
+ break;
default:
errno = EINVAL;
break;
diff --git a/unwind.h b/unwind.h
index 768e71e1..ad438ca9 100644
--- a/unwind.h
+++ b/unwind.h
@@ -150,7 +150,7 @@ extern "C" {
#endif
int jmp_save(struct jmp *);
-void jmp_restore(struct jmp *, int);
+noreturn void jmp_restore(struct jmp *, int);
#ifdef __cplusplus
}
diff --git a/utf8.c b/utf8.c
index 8afae187..9c286756 100644
--- a/utf8.c
+++ b/utf8.c
@@ -90,10 +90,10 @@ size_t utf8_from_buf(wchar_t *wdst, const unsigned char *src, size_t nbytes)
wch_min = 0x10000;
break;
}
- /* fallthrough */
#else
conversion_error();
#endif
+ /* fallthrough */
default:
if (wdst)
*wdst++ = 0xDC00 | ch;
@@ -321,10 +321,10 @@ wint_t utf8_decode(utf8_decoder_t *ud, int (*get)(mem_t *ctx), mem_t *ctx)
ud->wch_min = 0x10000;
break;
}
- /* fallthrough */
#else
conversion_error();
#endif
+ /* fallthrough */
default:
ud->back = ud->tail;
return 0xDC00 | ch;