Merge branch 'jk/war-on-sprintf'
authorJunio C Hamano <gitster@pobox.com>
Tue, 20 Oct 2015 22:24:00 +0000 (15:24 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 20 Oct 2015 22:24:01 +0000 (15:24 -0700)
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
...

20 files changed:
1  2 
Makefile
builtin/blame.c
builtin/fsck.c
builtin/gc.c
builtin/ls-remote.c
cache.h
connect.c
diff.c
dir.c
fast-import.c
git-compat-util.h
http.c
ll-merge.c
path.c
ref-filter.c
refs.c
setup.c
sha1_file.c
submodule.c
transport.c
diff --cc Makefile
Simple merge
diff --cc builtin/blame.c
Simple merge
diff --cc builtin/fsck.c
index b9a74f0cf6e169073994e466110fd1bde9febba7,d50efd5e8c158f945a4d0c02d3086927a3ab617b..8b8bb42c51d13ce9263c0a6fd30fa36810fef78c
@@@ -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 builtin/gc.c
Simple merge
Simple merge
diff --cc cache.h
Simple merge
diff --cc connect.c
Simple merge
diff --cc diff.c
Simple merge
diff --cc dir.c
Simple merge
diff --cc fast-import.c
Simple merge
Simple merge
diff --cc http.c
Simple merge
diff --cc ll-merge.c
Simple merge
diff --cc path.c
index 1352952616667a11c40060119f0e3a8da87a22f2,c105a9e083307395871ccf3b615c92ad0754fdd7..c740c4ff9403bc92df4c439839bd5596ac62e48d
--- 1/path.c
--- 2/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 ref-filter.c
Simple merge
diff --cc refs.c
Simple merge
diff --cc setup.c
Simple merge
diff --cc sha1_file.c
Simple merge
diff --cc submodule.c
index 5e5a46fe2ab765ff5ecec01a9bc46351fe596837,c480ed53b446e17ec3a25624846b018e4ae7c9f2..5879cfb158f0b581a54a56de5de44af5c2d0a700
@@@ -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;
 -      const char *git_dir;
+       int alloc;
  
 -      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;
diff --cc transport.c
Simple merge