From: Junio C Hamano Date: Wed, 17 Feb 2016 18:13:33 +0000 (-0800) Subject: Merge branch 'jk/rerere-xsnprintf' X-Git-Tag: v2.8.0-rc0~49 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/b1a90b68cfa3f9e1e0769c2c9fe0db012a51c818?ds=inline;hp=-c Merge branch 'jk/rerere-xsnprintf' Some calls to strcpy(3) triggers a false warning from static analysers that are less intelligent than humans, and reducing the number of these false hits helps us notice real issues. A few calls to strcpy(3) in "git rerere" that are already safe has been rewritten to avoid false wanings. * jk/rerere-xsnprintf: rerere: replace strcpy with xsnprintf --- b1a90b68cfa3f9e1e0769c2c9fe0db012a51c818 diff --combined rerere.c index 403c700c32,3d0fa8f551..587b7e2717 --- a/rerere.c +++ b/rerere.c @@@ -20,6 -20,8 +20,6 @@@ static int rerere_enabled = -1 /* automatically update cleanly resolved paths to the index */ static int rerere_autoupdate; -static char *merge_rr_path; - static void free_rerere_id(struct string_list_item *item) { free(item->util); @@@ -48,7 -50,7 +48,7 @@@ static int has_rerere_resolution(const static struct rerere_id *new_rerere_id_hex(char *hex) { struct rerere_id *id = xmalloc(sizeof(*id)); - strcpy(id->hex, hex); + xsnprintf(id->hex, sizeof(id->hex), "%s", hex); return id; } @@@ -67,7 -69,7 +67,7 @@@ static struct rerere_id *new_rerere_id( static void read_rr(struct string_list *rr) { struct strbuf buf = STRBUF_INIT; - FILE *in = fopen(merge_rr_path, "r"); + FILE *in = fopen(git_path_merge_rr(), "r"); if (!in) return; @@@ -545,8 -547,6 +545,8 @@@ static int find_conflict(struct string_ int rerere_remaining(struct string_list *merge_rr) { int i; + if (setup_rerere(merge_rr, RERERE_READONLY)) + return 0; if (read_cache() < 0) return error("Could not read index"); @@@ -767,21 -767,21 +767,21 @@@ static void git_rerere_config(void git_config(git_default_config, NULL); } +static GIT_PATH_FUNC(git_path_rr_cache, "rr-cache") + static int is_rerere_enabled(void) { - const char *rr_cache; int rr_cache_exists; if (!rerere_enabled) return 0; - rr_cache = git_path("rr-cache"); - rr_cache_exists = is_directory(rr_cache); + rr_cache_exists = is_directory(git_path_rr_cache()); if (rerere_enabled < 0) return rr_cache_exists; - if (!rr_cache_exists && mkdir_in_gitdir(rr_cache)) - die("Could not create directory %s", rr_cache); + if (!rr_cache_exists && mkdir_in_gitdir(git_path_rr_cache())) + die("Could not create directory %s", git_path_rr_cache()); return 1; } @@@ -795,11 -795,9 +795,11 @@@ int setup_rerere(struct string_list *me if (flags & (RERERE_AUTOUPDATE|RERERE_NOAUTOUPDATE)) rerere_autoupdate = !!(flags & RERERE_AUTOUPDATE); - merge_rr_path = git_pathdup("MERGE_RR"); - fd = hold_lock_file_for_update(&write_lock, merge_rr_path, - LOCK_DIE_ON_ERROR); + if (flags & RERERE_READONLY) + fd = 0; + else + fd = hold_lock_file_for_update(&write_lock, git_path_merge_rr(), + LOCK_DIE_ON_ERROR); read_rr(merge_rr); return fd; } @@@ -873,8 -871,6 +873,8 @@@ int rerere_forget(struct pathspec *path return error("Could not read index"); fd = setup_rerere(&merge_rr, RERERE_NOAUTOUPDATE); + if (fd < 0) + return 0; /* * The paths may have been resolved (incorrectly); @@@ -904,7 -900,7 +904,7 @@@ static struct rerere_id *dirname_to_id(const char *name) { static struct rerere_id id; - strcpy(id.hex, name); + xsnprintf(id.hex, sizeof(id.hex), "%s", name); return &id; } @@@ -950,9 -946,6 +950,9 @@@ void rerere_gc(struct string_list *rr int cutoff_noresolve = 15; int cutoff_resolve = 60; + if (setup_rerere(rr, 0) < 0) + return; + git_config_get_int("gc.rerereresolved", &cutoff_resolve); git_config_get_int("gc.rerereunresolved", &cutoff_noresolve); git_config(git_default_config, NULL); @@@ -981,7 -974,6 +981,7 @@@ for (i = 0; i < to_remove.nr; i++) unlink_rr_item(dirname_to_id(to_remove.items[i].string)); string_list_clear(&to_remove, 0); + rollback_lock_file(&write_lock); } /* @@@ -995,14 -987,10 +995,14 @@@ void rerere_clear(struct string_list *m { int i; + if (setup_rerere(merge_rr, 0) < 0) + return; + for (i = 0; i < merge_rr->nr; i++) { struct rerere_id *id = merge_rr->items[i].util; if (!has_rerere_resolution(id)) unlink_rr_item(id); } - unlink_or_warn(git_path("MERGE_RR")); + unlink_or_warn(git_path_merge_rr()); + rollback_lock_file(&write_lock); }