From: Junio C Hamano Date: Thu, 28 Sep 2017 05:47:53 +0000 (+0900) Subject: Merge branch 'jk/fallthrough' X-Git-Tag: v2.15.0-rc0~45 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/59373a4e03e273841c6c3b7fc9ac29c0a3e90c6d?hp=-c 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 --- 59373a4e03e273841c6c3b7fc9ac29c0a3e90c6d diff --combined builtin/cat-file.c index 1ea25331d3,aee280ea2c..f5fa4fd75a --- a/builtin/cat-file.c +++ b/builtin/cat-file.c @@@ -97,7 -97,7 +97,7 @@@ static int cat_one_file(int opt, const return !has_object_file(&oid); case 'w': - if (!path[0]) + if (!path) die("git cat-file --filters %s: must be " "", obj_name); @@@ -107,12 -107,13 +107,13 @@@ break; case 'c': - if (!path[0]) + if (!path) die("git cat-file --textconv %s: must be ", obj_name); if (textconv_object(path, obj_context.mode, &oid, 1, &buf, &size)) break; + /* else fallthrough */ case 'p': type = sha1_object_info(oid.hash, NULL); diff --combined config.c index a77cae56ed,08490dfe81..7ab37bacae --- a/config.c +++ b/config.c @@@ -2292,11 -2292,10 +2292,11 @@@ static int write_error(const char *file return 4; } -static int store_write_section(int fd, const char *key) +static ssize_t write_section(int fd, const char *key) { const char *dot; - int i, success; + int i; + ssize_t ret; struct strbuf sb = STRBUF_INIT; dot = memchr(key, '.', store.baselen); @@@ -2312,16 -2311,15 +2312,16 @@@ strbuf_addf(&sb, "[%.*s]\n", store.baselen, key); } - success = write_in_full(fd, sb.buf, sb.len) == sb.len; + ret = write_in_full(fd, sb.buf, sb.len); strbuf_release(&sb); - return success; + return ret; } -static int store_write_pair(int fd, const char *key, const char *value) +static ssize_t write_pair(int fd, const char *key, const char *value) { - int i, success; + int i; + ssize_t ret; int length = strlen(key + store.baselen + 1); const char *quote = ""; struct strbuf sb = STRBUF_INIT; @@@ -2355,16 -2353,17 +2355,17 @@@ case '"': case '\\': strbuf_addch(&sb, '\\'); + /* fallthrough */ default: strbuf_addch(&sb, value[i]); break; } strbuf_addf(&sb, "%s\n", quote); - success = write_in_full(fd, sb.buf, sb.len) == sb.len; + ret = write_in_full(fd, sb.buf, sb.len); strbuf_release(&sb); - return success; + return ret; } static ssize_t find_beginning_of_line(const char *contents, size_t size, @@@ -2493,8 -2492,8 +2494,8 @@@ int git_config_set_multivar_in_file_gen } store.key = (char *)key; - if (!store_write_section(fd, key) || - !store_write_pair(fd, key, value)) + if (write_section(fd, key) < 0 || + write_pair(fd, key, value) < 0) goto write_err_out; } else { struct stat st; @@@ -2604,10 -2603,11 +2605,10 @@@ /* write the first part of the config */ if (copy_end > copy_begin) { if (write_in_full(fd, contents + copy_begin, - copy_end - copy_begin) < - copy_end - copy_begin) + copy_end - copy_begin) < 0) goto write_err_out; if (new_line && - write_str_in_full(fd, "\n") != 1) + write_str_in_full(fd, "\n") < 0) goto write_err_out; } copy_begin = store.offset[i]; @@@ -2616,17 -2616,18 +2617,17 @@@ /* write the pair (value == NULL means unset) */ if (value != NULL) { if (store.state == START) { - if (!store_write_section(fd, key)) + if (write_section(fd, key) < 0) goto write_err_out; } - if (!store_write_pair(fd, key, value)) + if (write_pair(fd, key, value) < 0) goto write_err_out; } /* write the rest of the config */ if (copy_begin < contents_sz) if (write_in_full(fd, contents + copy_begin, - contents_sz - copy_begin) < - contents_sz - copy_begin) + contents_sz - copy_begin) < 0) goto write_err_out; munmap(contents, contents_sz); @@@ -2803,7 -2804,7 +2804,7 @@@ int git_config_rename_section_in_file(c continue; } store.baselen = strlen(new_name); - if (!store_write_section(out_fd, new_name)) { + if (write_section(out_fd, new_name) < 0) { ret = write_error(get_lock_file_path(lock)); goto out; } @@@ -2829,7 -2830,7 +2830,7 @@@ if (remove) continue; length = strlen(output); - if (write_in_full(out_fd, output, length) != length) { + if (write_in_full(out_fd, output, length) < 0) { ret = write_error(get_lock_file_path(lock)); goto out; } diff --combined read-cache.c index cdcd11c71e,a051567610..65f4fe8375 --- a/read-cache.c +++ b/read-cache.c @@@ -220,6 -220,7 +220,7 @@@ static int ce_modified_check_fs(const s case S_IFDIR: if (S_ISGITLINK(ce->ce_mode)) return ce_compare_gitlink(ce) ? DATA_CHANGED : 0; + /* else fallthrough */ default: return TYPE_CHANGED; } @@@ -1922,7 -1923,7 +1923,7 @@@ static int ce_write_flush(git_SHA_CTX * unsigned int buffered = write_buffer_len; if (buffered) { git_SHA1_Update(context, write_buffer, buffered); - if (write_in_full(fd, write_buffer, buffered) != buffered) + if (write_in_full(fd, write_buffer, buffered) < 0) return -1; write_buffer_len = 0; } @@@ -1971,7 -1972,7 +1972,7 @@@ static int ce_flush(git_SHA_CTX *contex /* Flush first if not enough space for SHA1 signature */ if (left + 20 > WRITE_BUFFER_SIZE) { - if (write_in_full(fd, write_buffer, left) != left) + if (write_in_full(fd, write_buffer, left) < 0) return -1; left = 0; } @@@ -1980,7 -1981,7 +1981,7 @@@ git_SHA1_Final(write_buffer + left, context); hashcpy(sha1, write_buffer + left); left += 20; - return (write_in_full(fd, write_buffer, left) != left) ? -1 : 0; + return (write_in_full(fd, write_buffer, left) < 0) ? -1 : 0; } static void ce_smudge_racily_clean_entry(struct cache_entry *ce) @@@ -2103,9 -2104,7 +2104,9 @@@ static int ce_write_entry(git_SHA_CTX * if (!result) result = ce_write(c, fd, to_remove_vi, prefix_size); if (!result) - result = ce_write(c, fd, ce->name + common, ce_namelen(ce) - common + 1); + result = ce_write(c, fd, ce->name + common, ce_namelen(ce) - common); + if (!result) + result = ce_write(c, fd, padding, 1); strbuf_splice(previous_name, common, to_remove, ce->name + common, ce_namelen(ce) - common);