summaryrefslogtreecommitdiff
path: root/src/patch_parse.c
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 /src/patch_parse.c
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.
Diffstat (limited to 'src/patch_parse.c')
-rw-r--r--src/patch_parse.c1
1 files changed, 1 insertions, 0 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;