summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2018-02-16 11:29:46 +0000
committerPatrick Steinhardt <ps@pks.im>2018-02-16 11:42:28 +0000
commit06b8a40f8b5eb1188a326d90705945b3a9b6a19f (patch)
tree3afb161bf4065ff0bdbdcb5f08171a677a507e1a
parent7c6e91759facc76e3f99373b759b4506fd700608 (diff)
downloadlibgit2-06b8a40f8b5eb1188a326d90705945b3a9b6a19f.tar.gz
Explicitly mark fallthrough cases with comments
A lot of compilers nowadays generate warnings when there are cases in a switch statement which implicitly fall through to the next case. To avoid this warning, the last line in the case that is falling through can have a comment matching a regular expression, where one possible comment body would be `/* fall through */`. An alternative to the comment would be an explicit attribute like e.g. `[[clang::fallthrough]` or `__attribute__ ((fallthrough))`. But GCC only introduced support for such an attribute recently with GCC 7. Thus, and also because the fallthrough comment is supported by most compilers, we settle for using comments instead. One shortcoming of that method is that compilers are very strict about that. Most interestingly, that comment _really_ has to be the last line. In case a closing brace follows the comment, the heuristic will fail.
-rw-r--r--src/patch_parse.c1
-rw-r--r--src/revparse.c5
-rw-r--r--src/tree.c2
-rw-r--r--src/util.c4
4 files changed, 6 insertions, 6 deletions
diff --git a/src/patch_parse.c b/src/patch_parse.c
index 27c01e96f..acdd45e82 100644
--- a/src/patch_parse.c
+++ b/src/patch_parse.c
@@ -575,6 +575,7 @@ static int parse_hunk_body(
switch (c) {
case '\n':
prefix = 0;
+ /* fall through */
case ' ':
origin = GIT_DIFF_LINE_CONTEXT;
diff --git a/src/revparse.c b/src/revparse.c
index 4ab4fb96d..7cb22f476 100644
--- a/src/revparse.c
+++ b/src/revparse.c
@@ -770,7 +770,6 @@ int revparse__ext(
}
case '@':
- {
if (spec[pos+1] == '{') {
git_object *temp_object = NULL;
@@ -786,10 +785,8 @@ int revparse__ext(
if (temp_object != NULL)
base_rev = temp_object;
break;
- } else {
- /* Fall through */
}
- }
+ /* fall through */
default:
if ((error = ensure_left_hand_identifier_is_not_known_yet(base_rev, reference)) < 0)
diff --git a/src/tree.c b/src/tree.c
index 6a136a6b7..fdf36f850 100644
--- a/src/tree.c
+++ b/src/tree.c
@@ -957,7 +957,7 @@ int git_tree_entry_bypath(
* walking down the path */
if (path[filename_len + 1] != '\0')
break;
-
+ /* fall through */
case '\0':
/* If there are no more components in the path, return
* this entry */
diff --git a/src/util.c b/src/util.c
index 1760a315e..b984b99ee 100644
--- a/src/util.c
+++ b/src/util.c
@@ -478,9 +478,11 @@ uint32_t git__hash(const void *key, int len, uint32_t seed)
switch(len & 3) {
case 3: k1 ^= tail[2] << 16;
+ /* fall through */
case 2: k1 ^= tail[1] << 8;
+ /* fall through */
case 1: k1 ^= tail[0];
- MURMUR_BLOCK();
+ MURMUR_BLOCK();
}
h1 ^= len;