Merge branch 'jk/fallthrough'

Many codepaths have been updated to squelch -Wimplicit-fallthrough
warnings from Gcc 7 (which is a good code hygiene).

* jk/fallthrough:
  consistently use "fallthrough" comments in switches
  curl_trace(): eliminate switch fallthrough
  test-line-buffer: simplify command parsing
maint
Junio C Hamano 2017-09-28 14:47:53 +09:00
commit 59373a4e03
15 changed files with 30 additions and 28 deletions

View File

@ -2920,6 +2920,7 @@ static int apply_one_fragment(struct apply_state *state,
if (plen && (ws_rule & WS_BLANK_AT_EOF) && if (plen && (ws_rule & WS_BLANK_AT_EOF) &&
ws_blank_line(patch + 1, plen, ws_rule)) ws_blank_line(patch + 1, plen, ws_rule))
is_blank_context = 1; is_blank_context = 1;
/* fallthrough */
case '-': case '-':
memcpy(old, patch + 1, plen); memcpy(old, patch + 1, plen);
add_line_info(&preimage, old, plen, add_line_info(&preimage, old, plen,
@ -2927,7 +2928,7 @@ static int apply_one_fragment(struct apply_state *state,
old += plen; old += plen;
if (first == '-') if (first == '-')
break; break;
/* Fall-through for ' ' */ /* fallthrough */
case '+': case '+':
/* --no-add does not add new lines */ /* --no-add does not add new lines */
if (first == '+' && state->no_add) if (first == '+' && state->no_add)

View File

@ -113,6 +113,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,


if (textconv_object(path, obj_context.mode, &oid, 1, &buf, &size)) if (textconv_object(path, obj_context.mode, &oid, 1, &buf, &size))
break; break;
/* else fallthrough */


case 'p': case 'p':
type = sha1_object_info(oid.hash, NULL); type = sha1_object_info(oid.hash, NULL);

View File

@ -436,6 +436,7 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o,
* update paths in the work tree, and we cannot revert * update paths in the work tree, and we cannot revert
* them. * them.
*/ */
/* fallthrough */
case 0: case 0:
return 0; return 0;
default: default:

View File

@ -57,7 +57,7 @@ static char *strip_escapes(const char *str, const char *service,
special = str[rpos]; special = str[rpos];
if (rpos == 1) if (rpos == 1)
break; break;
/* Fall-through to error. */ /* fallthrough */
default: default:
die("Bad remote-ext placeholder '%%%c'.", die("Bad remote-ext placeholder '%%%c'.",
str[rpos]); str[rpos]);

View File

@ -1189,6 +1189,7 @@ static int push_check(int argc, const char **argv, const char *prefix)
break; break;
die("HEAD does not match the named branch in the superproject"); die("HEAD does not match the named branch in the superproject");
} }
/* fallthrough */
default: default:
die("src refspec '%s' must name a ref", die("src refspec '%s' must name a ref",
rs->src); rs->src);

View File

@ -2355,6 +2355,7 @@ static ssize_t write_pair(int fd, const char *key, const char *value)
case '"': case '"':
case '\\': case '\\':
strbuf_addch(&sb, '\\'); strbuf_addch(&sb, '\\');
/* fallthrough */
default: default:
strbuf_addch(&sb, value[i]); strbuf_addch(&sb, value[i]);
break; break;

View File

@ -1545,8 +1545,9 @@ static int ident_filter_fn(struct stream_filter *filter,
switch (ident->state) { switch (ident->state) {
default: default:
strbuf_add(&ident->left, head, ident->state); strbuf_add(&ident->left, head, ident->state);
/* fallthrough */
case IDENT_SKIPPING: case IDENT_SKIPPING:
/* fallthru */ /* fallthrough */
case IDENT_DRAINING: case IDENT_DRAINING:
ident_drain(ident, &output, osize_p); ident_drain(ident, &output, osize_p);
} }

1
fsck.c
View File

@ -588,6 +588,7 @@ static int fsck_tree(struct tree *item, struct fsck_options *options)
case S_IFREG | 0664: case S_IFREG | 0664:
if (!options->strict) if (!options->strict)
break; break;
/* fallthrough */
default: default:
has_bad_modes = 1; has_bad_modes = 1;
} }

View File

@ -1523,6 +1523,7 @@ static int remote_exists(const char *path)
break; break;
case HTTP_ERROR: case HTTP_ERROR:
error("unable to access '%s': %s", url, curl_errorstr); error("unable to access '%s': %s", url, curl_errorstr);
/* fallthrough */
default: default:
ret = -1; ret = -1;
} }

7
http.c
View File

@ -638,9 +638,7 @@ static int curl_trace(CURL *handle, curl_infotype type, char *data, size_t size,
switch (type) { switch (type) {
case CURLINFO_TEXT: case CURLINFO_TEXT:
trace_printf_key(&trace_curl, "== Info: %s", data); trace_printf_key(&trace_curl, "== Info: %s", data);
default: /* we ignore unknown types by default */ break;
return 0;

case CURLINFO_HEADER_OUT: case CURLINFO_HEADER_OUT:
text = "=> Send header"; text = "=> Send header";
curl_dump_header(text, (unsigned char *)data, size, DO_FILTER); curl_dump_header(text, (unsigned char *)data, size, DO_FILTER);
@ -665,6 +663,9 @@ static int curl_trace(CURL *handle, curl_infotype type, char *data, size_t size,
text = "<= Recv SSL data"; text = "<= Recv SSL data";
curl_dump_data(text, (unsigned char *)data, size); curl_dump_data(text, (unsigned char *)data, size);
break; break;

default: /* we ignore unknown types by default */
return 0;
} }
return 0; return 0;
} }

View File

@ -822,6 +822,7 @@ static void handle_filter(struct mailinfo *mi, struct strbuf *line)
if (!handle_commit_msg(mi, line)) if (!handle_commit_msg(mi, line))
break; break;
mi->filter_stage++; mi->filter_stage++;
/* fallthrough */
case 1: case 1:
handle_patch(mi, line); handle_patch(mi, line);
break; break;

View File

@ -431,6 +431,7 @@ void tcl_quote_buf(struct strbuf *sb, const char *src)
case '{': case '}': case '{': case '}':
case '$': case '\\': case '"': case '$': case '\\': case '"':
strbuf_addch(sb, '\\'); strbuf_addch(sb, '\\');
/* fallthrough */
default: default:
strbuf_addch(sb, c); strbuf_addch(sb, c);
break; break;

View File

@ -220,6 +220,7 @@ static int ce_modified_check_fs(const struct cache_entry *ce, struct stat *st)
case S_IFDIR: case S_IFDIR:
if (S_ISGITLINK(ce->ce_mode)) if (S_ISGITLINK(ce->ce_mode))
return ce_compare_gitlink(ce) ? DATA_CHANGED : 0; return ce_compare_gitlink(ce) ? DATA_CHANGED : 0;
/* else fallthrough */
default: default:
return TYPE_CHANGED; return TYPE_CHANGED;
} }

View File

@ -497,7 +497,7 @@ int send_pack(struct send_pack_args *args,
strbuf_release(&cap_buf); strbuf_release(&cap_buf);
return atomic_push_failure(args, remote_refs, ref); return atomic_push_failure(args, remote_refs, ref);
} }
/* Fallthrough for non atomic case. */ /* else fallthrough */
default: default:
continue; continue;
} }

View File

@ -17,27 +17,17 @@ static uint32_t strtouint32(const char *s)


static void handle_command(const char *command, const char *arg, struct line_buffer *buf) static void handle_command(const char *command, const char *arg, struct line_buffer *buf)
{ {
switch (*command) { if (starts_with(command, "binary ")) {
case 'b': struct strbuf sb = STRBUF_INIT;
if (starts_with(command, "binary ")) { strbuf_addch(&sb, '>');
struct strbuf sb = STRBUF_INIT; buffer_read_binary(buf, &sb, strtouint32(arg));
strbuf_addch(&sb, '>'); fwrite(sb.buf, 1, sb.len, stdout);
buffer_read_binary(buf, &sb, strtouint32(arg)); strbuf_release(&sb);
fwrite(sb.buf, 1, sb.len, stdout); } else if (starts_with(command, "copy ")) {
strbuf_release(&sb); buffer_copy_bytes(buf, strtouint32(arg));
return; } else if (starts_with(command, "skip ")) {
} buffer_skip_bytes(buf, strtouint32(arg));
case 'c': } else {
if (starts_with(command, "copy ")) {
buffer_copy_bytes(buf, strtouint32(arg));
return;
}
case 's':
if (starts_with(command, "skip ")) {
buffer_skip_bytes(buf, strtouint32(arg));
return;
}
default:
die("unrecognized command: %s", command); die("unrecognized command: %s", command);
} }
} }