From: Junio C Hamano Date: Tue, 20 Oct 2015 22:24:00 +0000 (-0700) Subject: Merge branch 'jk/war-on-sprintf' X-Git-Tag: v2.7.0-rc0~87 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/78891795df91a313fac590dd6cff9d8aace0dc9a Merge branch 'jk/war-on-sprintf' Many allocations that is manually counted (correctly) that are followed by strcpy/sprintf have been replaced with a less error prone constructs such as xstrfmt. Macintosh-specific breakage was noticed and corrected in this reroll. * jk/war-on-sprintf: (70 commits) name-rev: use strip_suffix to avoid magic numbers use strbuf_complete to conditionally append slash fsck: use for_each_loose_file_in_objdir Makefile: drop D_INO_IN_DIRENT build knob fsck: drop inode-sorting code convert strncpy to memcpy notes: document length of fanout path with a constant color: add color_set helper for copying raw colors prefer memcpy to strcpy help: clean up kfmclient munging receive-pack: simplify keep_arg computation avoid sprintf and strcpy with flex arrays use alloc_ref rather than hand-allocating "struct ref" color: add overflow checks for parsing colors drop strcpy in favor of raw sha1_to_hex use sha1_to_hex_r() instead of strcpy daemon: use cld->env_array when re-spawning stat_tracking_info: convert to argv_array http-push: use an argv_array for setup_revisions fetch-pack: use argv_array for index-pack / unpack-objects ... --- 78891795df91a313fac590dd6cff9d8aace0dc9a diff --cc builtin/fsck.c index b9a74f0cf6,d50efd5e8c..8b8bb42c51 --- a/builtin/fsck.c +++ b/builtin/fsck.c @@@ -38,16 -38,7 +38,8 @@@ static int show_dangling = 1 #define ERROR_OBJECT 01 #define ERROR_REACHABLE 02 #define ERROR_PACK 04 +#define ERROR_REFS 010 - #ifdef NO_D_INO_IN_DIRENT - #define SORT_DIRENT 0 - #define DIRENT_SORT_HINT(de) 0 - #else - #define SORT_DIRENT 1 - #define DIRENT_SORT_HINT(de) ((de)->d_ino) - #endif - static int fsck_config(const char *var, const char *value, void *cb) { if (strcmp(var, "fsck.skiplist") == 0) { diff --cc path.c index 1352952616,c105a9e083..c740c4ff94 --- a/path.c +++ b/path.c @@@ -448,12 -238,9 +458,11 @@@ static void do_submodule_path(struct st const char *fmt, va_list args) { const char *git_dir; + struct strbuf git_submodule_common_dir = STRBUF_INIT; + struct strbuf git_submodule_dir = STRBUF_INIT; strbuf_addstr(buf, path); - if (buf->len && buf->buf[buf->len - 1] != '/') - strbuf_addch(buf, '/'); + strbuf_complete(buf, '/'); strbuf_addstr(buf, ".git"); git_dir = read_gitfile(buf->buf); @@@ -661,22 -439,20 +669,24 @@@ const char *enter_repo(const char *path } if (!suffix[i]) return NULL; - gitfile = read_gitfile(used_path); - if (gitfile) - strcpy(used_path, gitfile); - if (chdir(used_path)) - gitfile = read_gitfile(used_path.buf) ; ++ gitfile = read_gitfile(used_path.buf); + if (gitfile) { + strbuf_reset(&used_path); + strbuf_addstr(&used_path, gitfile); + } + if (chdir(used_path.buf)) return NULL; - path = validated_path; + path = validated_path.buf; } - else if (chdir(path)) - return NULL; + else { + const char *gitfile = read_gitfile(path); + if (gitfile) + path = gitfile; + if (chdir(path)) + return NULL; + } - if (access("objects", X_OK) == 0 && access("refs", X_OK) == 0 && - validate_headref("HEAD") == 0) { + if (is_git_directory(".")) { set_git_dir("."); check_repository_format(); return path; diff --cc submodule.c index 5e5a46fe2a,c480ed53b4..5879cfb158 --- a/submodule.c +++ b/submodule.c @@@ -122,8 -122,16 +122,9 @@@ static int add_submodule_odb(const cha struct strbuf objects_directory = STRBUF_INIT; struct alternate_object_database *alt_odb; int ret = 0; + int alloc; - const char *git_dir; - strbuf_addf(&objects_directory, "%s/.git", path); - git_dir = read_gitfile(objects_directory.buf); - if (git_dir) { - strbuf_reset(&objects_directory); - strbuf_addstr(&objects_directory, git_dir); - } - strbuf_addstr(&objects_directory, "/objects/"); + strbuf_git_path_submodule(&objects_directory, path, "objects/"); if (!is_directory(objects_directory.buf)) { ret = -1; goto done;