Commit 78891795 authored by Junio C Hamano's avatar Junio C Hamano

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
  ...
parents 614a2ace 34e02deb
......@@ -74,8 +74,6 @@ all::
# Define HAVE_PATHS_H if you have paths.h and want to use the default PATH
# it specifies.
#
# Define NO_D_INO_IN_DIRENT if you don't have d_ino in your struct dirent.
#
# Define NO_D_TYPE_IN_DIRENT if your platform defines DT_UNKNOWN but lacks
# d_type in struct dirent (Cygwin 1.5, fixed in Cygwin 1.7).
#
......@@ -1164,9 +1162,6 @@ endif
ifdef NO_D_TYPE_IN_DIRENT
BASIC_CFLAGS += -DNO_D_TYPE_IN_DIRENT
endif
ifdef NO_D_INO_IN_DIRENT
BASIC_CFLAGS += -DNO_D_INO_IN_DIRENT
endif
ifdef NO_GECOS_IN_PWENT
BASIC_CFLAGS += -DNO_GECOS_IN_PWENT
endif
......
......@@ -167,21 +167,21 @@ static void prepare_header(struct archiver_args *args,
struct ustar_header *header,
unsigned int mode, unsigned long size)
{
sprintf(header->mode, "%07o", mode & 07777);
sprintf(header->size, "%011lo", S_ISREG(mode) ? size : 0);
sprintf(header->mtime, "%011lo", (unsigned long) args->time);
xsnprintf(header->mode, sizeof(header->mode), "%07o", mode & 07777);
xsnprintf(header->size, sizeof(header->size), "%011lo", S_ISREG(mode) ? size : 0);
xsnprintf(header->mtime, sizeof(header->mtime), "%011lo", (unsigned long) args->time);
sprintf(header->uid, "%07o", 0);
sprintf(header->gid, "%07o", 0);
xsnprintf(header->uid, sizeof(header->uid), "%07o", 0);
xsnprintf(header->gid, sizeof(header->gid), "%07o", 0);
strlcpy(header->uname, "root", sizeof(header->uname));
strlcpy(header->gname, "root", sizeof(header->gname));
sprintf(header->devmajor, "%07o", 0);
sprintf(header->devminor, "%07o", 0);
xsnprintf(header->devmajor, sizeof(header->devmajor), "%07o", 0);
xsnprintf(header->devminor, sizeof(header->devminor), "%07o", 0);
memcpy(header->magic, "ustar", 6);
memcpy(header->version, "00", 2);
sprintf(header->chksum, "%07o", ustar_header_chksum(header));
snprintf(header->chksum, sizeof(header->chksum), "%07o", ustar_header_chksum(header));
}
static int write_extended_header(struct archiver_args *args,
......@@ -193,7 +193,7 @@ static int write_extended_header(struct archiver_args *args,
memset(&header, 0, sizeof(header));
*header.typeflag = TYPEFLAG_EXT_HEADER;
mode = 0100666;
sprintf(header.name, "%s.paxheader", sha1_to_hex(sha1));
xsnprintf(header.name, sizeof(header.name), "%s.paxheader", sha1_to_hex(sha1));
prepare_header(args, &header, mode, size);
write_blocked(&header, sizeof(header));
write_blocked(buffer, size);
......@@ -233,10 +233,10 @@ static int write_tar_entry(struct archiver_args *args,
size_t rest = pathlen - plen - 1;
if (plen > 0 && rest <= sizeof(header.name)) {
memcpy(header.prefix, path, plen);
memcpy(header.name, path + plen + 1, rest);
memcpy(header.name, path + plen + 1, rest);
} else {
sprintf(header.name, "%s.data",
sha1_to_hex(sha1));
xsnprintf(header.name, sizeof(header.name), "%s.data",
sha1_to_hex(sha1));
strbuf_append_ext_header(&ext_header, "path",
path, pathlen);
}
......@@ -259,8 +259,8 @@ static int write_tar_entry(struct archiver_args *args,
if (S_ISLNK(mode)) {
if (size > sizeof(header.linkname)) {
sprintf(header.linkname, "see %s.paxheader",
sha1_to_hex(sha1));
xsnprintf(header.linkname, sizeof(header.linkname),
"see %s.paxheader", sha1_to_hex(sha1));
strbuf_append_ext_header(&ext_header, "linkpath",
buffer, size);
} else
......@@ -301,7 +301,7 @@ static int write_global_extended_header(struct archiver_args *args)
memset(&header, 0, sizeof(header));
*header.typeflag = TYPEFLAG_GLOBAL_HEADER;
mode = 0100666;
strcpy(header.name, "pax_global_header");
xsnprintf(header.name, sizeof(header.name), "pax_global_header");
prepare_header(args, &header, mode, ext_header.len);
write_blocked(&header, sizeof(header));
write_blocked(ext_header.buf, ext_header.len);
......
......@@ -171,13 +171,14 @@ static void queue_directory(const unsigned char *sha1,
unsigned mode, int stage, struct archiver_context *c)
{
struct directory *d;
d = xmallocz(sizeof(*d) + base->len + 1 + strlen(filename));
size_t len = base->len + 1 + strlen(filename) + 1;
d = xmalloc(sizeof(*d) + len);
d->up = c->bottom;
d->baselen = base->len;
d->mode = mode;
d->stage = stage;
c->bottom = d;
d->len = sprintf(d->path, "%.*s%s/", (int)base->len, base->buf, filename);
d->len = xsnprintf(d->path, len, "%.*s%s/", (int)base->len, base->buf, filename);
hashcpy(d->oid.hash, sha1);
}
......
......@@ -77,8 +77,7 @@ static enum ws_ignore {
static const char *patch_input_file;
static const char *root;
static int root_len;
static struct strbuf root = STRBUF_INIT;
static int read_stdin = 1;
static int options;
......@@ -494,8 +493,8 @@ static char *find_name_gnu(const char *line, const char *def, int p_value)
}
strbuf_remove(&name, 0, cp - name.buf);
if (root)
strbuf_insert(&name, 0, root, root_len);
if (root.len)
strbuf_insert(&name, 0, root.buf, root.len);
return squash_slash(strbuf_detach(&name, NULL));
}
......@@ -697,11 +696,8 @@ static char *find_name_common(const char *line, const char *def,
return squash_slash(xstrdup(def));
}
if (root) {
char *ret = xmalloc(root_len + len + 1);
strcpy(ret, root);
memcpy(ret + root_len, start, len);
ret[root_len + len] = '\0';
if (root.len) {
char *ret = xstrfmt("%s%.*s", root.buf, len, start);
return squash_slash(ret);
}
......@@ -1277,8 +1273,8 @@ static int parse_git_header(const char *line, int len, unsigned int size, struct
* the default name from the header.
*/
patch->def_name = git_header_name(line, len);
if (patch->def_name && root) {
char *s = xstrfmt("%s%s", root, patch->def_name);
if (patch->def_name && root.len) {
char *s = xstrfmt("%s%s", root.buf, patch->def_name);
free(patch->def_name);
patch->def_name = s;
}
......@@ -4501,14 +4497,9 @@ static int option_parse_whitespace(const struct option *opt,
static int option_parse_directory(const struct option *opt,
const char *arg, int unset)
{
root_len = strlen(arg);
if (root_len && arg[root_len - 1] != '/') {
char *new_root;
root = new_root = xmalloc(root_len + 2);
strcpy(new_root, arg);
strcpy(new_root + root_len++, "/");
} else
root = arg;
strbuf_reset(&root);
strbuf_addstr(&root, arg);
strbuf_complete(&root, '/');
return 0;
}
......
......@@ -459,12 +459,13 @@ static void queue_blames(struct scoreboard *sb, struct origin *porigin,
static struct origin *make_origin(struct commit *commit, const char *path)
{
struct origin *o;
o = xcalloc(1, sizeof(*o) + strlen(path) + 1);
size_t pathlen = strlen(path) + 1;
o = xcalloc(1, sizeof(*o) + pathlen);
o->commit = commit;
o->refcnt = 1;
o->next = commit->util;
commit->util = o;
strcpy(o->path, path);
memcpy(o->path, path, pathlen); /* includes NUL */
return o;
}
......@@ -1879,9 +1880,9 @@ static void emit_porcelain(struct scoreboard *sb, struct blame_entry *ent,
int cnt;
const char *cp;
struct origin *suspect = ent->suspect;
char hex[41];
char hex[GIT_SHA1_HEXSZ + 1];
strcpy(hex, sha1_to_hex(suspect->commit->object.sha1));
sha1_to_hex_r(hex, suspect->commit->object.sha1);
printf("%s %d %d %d\n",
hex,
ent->s_lno + 1,
......@@ -1917,11 +1918,11 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)
const char *cp;
struct origin *suspect = ent->suspect;
struct commit_info ci;
char hex[41];
char hex[GIT_SHA1_HEXSZ + 1];
int show_raw_time = !!(opt & OUTPUT_RAW_TIMESTAMP);
get_commit_info(suspect->commit, &ci, 1);
strcpy(hex, sha1_to_hex(suspect->commit->object.sha1));
sha1_to_hex_r(hex, suspect->commit->object.sha1);
cp = nth_line(sb, ent->lno);
for (cnt = 0; cnt < ent->num_lines; cnt++) {
......
......@@ -159,8 +159,7 @@ static int is_git_repository(struct strbuf *path)
int gitfile_error;
size_t orig_path_len = path->len;
assert(orig_path_len != 0);
if (path->buf[orig_path_len - 1] != '/')
strbuf_addch(path, '/');
strbuf_complete(path, '/');
strbuf_addstr(path, ".git");
if (read_gitfile_gently(path->buf, &gitfile_error) || is_git_directory(path->buf))
ret = 1;
......@@ -206,8 +205,7 @@ static int remove_dirs(struct strbuf *path, const char *prefix, int force_flag,
return res;
}
if (path->buf[original_len - 1] != '/')
strbuf_addch(path, '/');
strbuf_complete(path, '/');
len = path->len;
while ((e = readdir(dir)) != NULL) {
......
......@@ -246,8 +246,6 @@ static int get_value(const char *key_, const char *regex_)
static char *normalize_value(const char *key, const char *value)
{
char *normalized;
if (!value)
return NULL;
......@@ -258,27 +256,21 @@ static char *normalize_value(const char *key, const char *value)
* "~/foobar/" in the config file, and to expand the ~
* when retrieving the value.
*/
normalized = xstrdup(value);
else {
normalized = xmalloc(64);
if (types == TYPE_INT) {
int64_t v = git_config_int64(key, value);
sprintf(normalized, "%"PRId64, v);
}
else if (types == TYPE_BOOL)
sprintf(normalized, "%s",
git_config_bool(key, value) ? "true" : "false");
else if (types == TYPE_BOOL_OR_INT) {
int is_bool, v;
v = git_config_bool_or_int(key, value, &is_bool);
if (!is_bool)
sprintf(normalized, "%d", v);
else
sprintf(normalized, "%s", v ? "true" : "false");
}
return xstrdup(value);
if (types == TYPE_INT)
return xstrfmt("%"PRId64, git_config_int64(key, value));
if (types == TYPE_BOOL)
return xstrdup(git_config_bool(key, value) ? "true" : "false");
if (types == TYPE_BOOL_OR_INT) {
int is_bool, v;
v = git_config_bool_or_int(key, value, &is_bool);
if (!is_bool)
return xstrfmt("%d", v);
else
return xstrdup(v ? "true" : "false");
}
return normalized;
die("BUG: cannot normalize type %d", types);
}
static int get_color_found;
......
......@@ -528,36 +528,38 @@ static int update_local_ref(struct ref *ref,
}
if (in_merge_bases(current, updated)) {
char quickref[83];
struct strbuf quickref = STRBUF_INIT;
int r;
strcpy(quickref, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));
strcat(quickref, "..");
strcat(quickref, find_unique_abbrev(ref->new_sha1, DEFAULT_ABBREV));
strbuf_add_unique_abbrev(&quickref, current->object.sha1, DEFAULT_ABBREV);
strbuf_addstr(&quickref, "..");
strbuf_add_unique_abbrev(&quickref, ref->new_sha1, DEFAULT_ABBREV);
if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
(recurse_submodules != RECURSE_SUBMODULES_ON))
check_for_new_submodule_commits(ref->new_sha1);
r = s_update_ref("fast-forward", ref, 1);
strbuf_addf(display, "%c %-*s %-*s -> %s%s",
r ? '!' : ' ',
TRANSPORT_SUMMARY_WIDTH, quickref,
TRANSPORT_SUMMARY_WIDTH, quickref.buf,
REFCOL_WIDTH, remote, pretty_ref,
r ? _(" (unable to update local ref)") : "");
strbuf_release(&quickref);
return r;
} else if (force || ref->force) {
char quickref[84];
struct strbuf quickref = STRBUF_INIT;
int r;
strcpy(quickref, find_unique_abbrev(current->object.sha1, DEFAULT_ABBREV));
strcat(quickref, "...");
strcat(quickref, find_unique_abbrev(ref->new_sha1, DEFAULT_ABBREV));
strbuf_add_unique_abbrev(&quickref, current->object.sha1, DEFAULT_ABBREV);
strbuf_addstr(&quickref, "...");
strbuf_add_unique_abbrev(&quickref, ref->new_sha1, DEFAULT_ABBREV);
if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
(recurse_submodules != RECURSE_SUBMODULES_ON))
check_for_new_submodule_commits(ref->new_sha1);
r = s_update_ref("forced-update", ref, 1);
strbuf_addf(display, "%c %-*s %-*s -> %s (%s)",
r ? '!' : '+',
TRANSPORT_SUMMARY_WIDTH, quickref,
TRANSPORT_SUMMARY_WIDTH, quickref.buf,
REFCOL_WIDTH, remote, pretty_ref,
r ? _("unable to update local ref") : _("forced update"));
strbuf_release(&quickref);
return r;
} else {
strbuf_addf(display, "! %-*s %-*s -> %s %s",
......@@ -637,8 +639,7 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
continue;
if (rm->peer_ref) {
ref = xcalloc(1, sizeof(*ref) + strlen(rm->peer_ref->name) + 1);
strcpy(ref->name, rm->peer_ref->name);
ref = alloc_ref(rm->peer_ref->name);
hashcpy(ref->old_sha1, rm->peer_ref->old_sha1);
hashcpy(ref->new_sha1, rm->old_sha1);
ref->force = rm->peer_ref->force;
......@@ -1156,11 +1157,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
die(_("--depth and --unshallow cannot be used together"));
else if (!is_repository_shallow())
die(_("--unshallow on a complete repository does not make sense"));
else {
static char inf_depth[12];
sprintf(inf_depth, "%d", INFINITE_DEPTH);
depth = inf_depth;
}
else
depth = xstrfmt("%d", INFINITE_DEPTH);
}
/* no need to be strict, transport_set_option() will validate it again */
......
......@@ -40,14 +40,6 @@ static int show_dangling = 1;
#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) {
......@@ -374,102 +366,6 @@ static int fsck_obj_buffer(const unsigned char *sha1, enum object_type type,
return fsck_obj(obj);
}
/*
* This is the sorting chunk size: make it reasonably
* big so that we can sort well..
*/
#define MAX_SHA1_ENTRIES (1024)
struct sha1_entry {
unsigned long ino;
unsigned char sha1[20];
};
static struct {
unsigned long nr;
struct sha1_entry *entry[MAX_SHA1_ENTRIES];
} sha1_list;
static int ino_compare(const void *_a, const void *_b)
{
const struct sha1_entry *a = _a, *b = _b;
unsigned long ino1 = a->ino, ino2 = b->ino;
return ino1 < ino2 ? -1 : ino1 > ino2 ? 1 : 0;
}
static void fsck_sha1_list(void)
{
int i, nr = sha1_list.nr;
if (SORT_DIRENT)
qsort(sha1_list.entry, nr,
sizeof(struct sha1_entry *), ino_compare);
for (i = 0; i < nr; i++) {
struct sha1_entry *entry = sha1_list.entry[i];
unsigned char *sha1 = entry->sha1;
sha1_list.entry[i] = NULL;
if (fsck_sha1(sha1))
errors_found |= ERROR_OBJECT;
free(entry);
}
sha1_list.nr = 0;
}
static void add_sha1_list(unsigned char *sha1, unsigned long ino)
{
struct sha1_entry *entry = xmalloc(sizeof(*entry));
int nr;
entry->ino = ino;
hashcpy(entry->sha1, sha1);
nr = sha1_list.nr;
if (nr == MAX_SHA1_ENTRIES) {
fsck_sha1_list();
nr = 0;
}
sha1_list.entry[nr] = entry;
sha1_list.nr = ++nr;
}
static inline int is_loose_object_file(struct dirent *de,
char *name, unsigned char *sha1)
{
if (strlen(de->d_name) != 38)
return 0;
memcpy(name + 2, de->d_name, 39);
return !get_sha1_hex(name, sha1);
}
static void fsck_dir(int i, char *path)
{
DIR *dir = opendir(path);
struct dirent *de;
char name[100];
if (!dir)
return;
if (verbose)
fprintf(stderr, "Checking directory %s\n", path);
sprintf(name, "%02x", i);
while ((de = readdir(dir)) != NULL) {
unsigned char sha1[20];
if (is_dot_or_dotdot(de->d_name))
continue;
if (is_loose_object_file(de, name, sha1)) {
add_sha1_list(sha1, DIRENT_SORT_HINT(de));
continue;
}
if (starts_with(de->d_name, "tmp_obj_"))
continue;
fprintf(stderr, "bad sha1 file: %s/%s\n", path, de->d_name);
}
closedir(dir);
}
static int default_refs;
static void fsck_handle_reflog_sha1(const char *refname, unsigned char *sha1)
......@@ -559,9 +455,28 @@ static void get_default_heads(void)
}
}
static int fsck_loose(const unsigned char *sha1, const char *path, void *data)
{
if (fsck_sha1(sha1))
errors_found |= ERROR_OBJECT;
return 0;
}
static int fsck_cruft(const char *basename, const char *path, void *data)
{
if (!starts_with(basename, "tmp_obj_"))
fprintf(stderr, "bad sha1 file: %s\n", path);
return 0;
}
static int fsck_subdir(int nr, const char *path, void *progress)
{
display_progress(progress, nr + 1);
return 0;
}
static void fsck_object_dir(const char *path)
{
int i;
struct progress *progress = NULL;
if (verbose)
......@@ -569,14 +484,11 @@ static void fsck_object_dir(const char *path)
if (show_progress)
progress = start_progress(_("Checking object directories"), 256);
for (i = 0; i < 256; i++) {
static char dir[4096];
sprintf(dir, "%s/%02x", path, i);
fsck_dir(i, dir);
display_progress(progress, i+1);
}
for_each_loose_file_in_objdir(path, fsck_loose, fsck_cruft, fsck_subdir,
progress);
display_progress(progress, 256);
stop_progress(&progress);
fsck_sha1_list();
}
static int fsck_head_link(void)
......@@ -688,16 +600,18 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
git_config(fsck_config, NULL);
fsck_head_link();
if (!connectivity_only)
if (!connectivity_only) {
fsck_object_dir(get_object_directory());
prepare_alt_odb();
for (alt = alt_odb_list; alt; alt = alt->next) {
char namebuf[PATH_MAX];
int namelen = alt->name - alt->base;
memcpy(namebuf, alt->base, namelen);
namebuf[namelen - 1] = 0;
fsck_object_dir(namebuf);
prepare_alt_odb();
for (alt = alt_odb_list; alt; alt = alt->next) {
/* directory name, minus trailing slash */
size_t namelen = alt->name - alt->base - 1;
struct strbuf name = STRBUF_INIT;
strbuf_add(&name, alt->base, namelen);
fsck_object_dir(name.buf);
strbuf_release(&name);
}
}
if (check_full) {
......
......@@ -217,7 +217,7 @@ static const char *lock_repo_for_gc(int force, pid_t* ret_pid)
return NULL;
if (gethostname(my_host, sizeof(my_host)))
strcpy(my_host, "unknown");
xsnprintf(my_host, sizeof(my_host), "unknown");
pidfile_path = git_pathdup("gc.pid");
fd = hold_lock_file_for_update(&lock, pidfile_path,
......
......@@ -140,17 +140,10 @@ static void exec_man_konqueror(const char *path, const char *page)
/* It's simpler to launch konqueror using kfmclient. */
if (path) {
const char *file = strrchr(path, '/');
if (file && !strcmp(file + 1, "konqueror")) {
char *new = xstrdup(path);
char *dest = strrchr(new, '/');
/* strlen("konqueror") == strlen("kfmclient") */
strcpy(dest + 1, "kfmclient");
path = new;
}
if (file)
filename = file;
size_t len;
if (strip_suffix(path, "/konqueror", &len))
path = xstrfmt("%.*s/kfmclient", (int)len, path);
filename = basename((char *)path);
} else
path = "kfmclient";
strbuf_addf(&man_page, "man:%s(1)", page);
......@@ -183,7 +176,7 @@ static void add_man_viewer(const char *name)
while (*p)
p = &((*p)->next);
*p = xcalloc(1, (sizeof(**p) + len + 1));
strncpy((*p)->name, name, len);
memcpy((*p)->name, name, len); /* NUL-terminated by xcalloc */
}
static int supported_man_viewer(const char *name, size_t len)
......@@ -199,7 +192,7 @@ static void do_add_man_viewer_info(const char *name,
{
struct man_viewer_info_list *new = xcalloc(1, sizeof(*new) + len + 1);
strncpy(new->name, name, len);
memcpy(new->name, name, len); /* NUL-terminated by xcalloc */
new->info = xstrdup(value);
new->next = man_viewer_info_list;
man_viewer_info_list = new;
......@@ -295,16 +288,6 @@ static int is_git_command(const char *s)
is_in_cmdlist(&other_cmds, s);
}
static const char *prepend(const char *prefix, const char *cmd)
{
size_t pre_len = strlen(prefix);
size_t cmd_len = strlen(cmd);
char *p = xmalloc(pre_len + cmd_len + 1);
memcpy(p, prefix, pre_len);
strcpy(p + pre_len, cmd);
return p;
}
static const char *cmd_to_page(const char *git_cmd)
{
if (!git_cmd)
......@@ -312,9 +295,9 @@ static const char *cmd_to_page(const char *git_cmd)
else if (starts_with(git_cmd, "git"))
return git_cmd;
else if (is_git_command(git_cmd))
return prepend("git-", git_cmd);
return xstrfmt("git-%s", git_cmd);
else
return prepend("git", git_cmd);
return xstrfmt("git%s", git_cmd);
}
static void setup_man_path(void)
......
......@@ -441,7 +441,7 @@ static void *unpack_entry_data(unsigned long offset, unsigned long size,
int hdrlen;
if (!is_delta_type(type)) {
hdrlen = sprintf(hdr, "%s %lu", typename(type), size) + 1;
hdrlen = xsnprintf(hdr, sizeof(hdr), "%s %lu", typename(type), size) + 1;
git_SHA1_Init(&c);
git_SHA1_Update(&c, hdr, hdrlen);
} else
......
This diff is collapsed.
......@@ -796,8 +796,7 @@ static int reopen_stdout(struct commit *commit, const char *subject,
if (filename.len >=
PATH_MAX - FORMAT_PATCH_NAME_MAX - suffix_len)
return error(_("name of output directory is too long"));
if (filename.buf[filename.len - 1] != '/')
strbuf_addch(&filename, '/');
strbuf_complete(&filename, '/');
}
if (rev->numbered_files)
......
......@@ -93,12 +93,8 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix)
if (argv[i]) {
int j;
pattern = xcalloc(argc - i + 1, sizeof(const char *));
for (j = i; j < argc; j++) {
int len = strlen(argv[j]);
char *p = xmalloc(len + 3);
sprintf(p, "*/%s", argv[j]);
pattern[j - i] = p;
}
for (j = i; j < argc; j++)
pattern[j - i] = xstrfmt("*/%s", argv[j]);
}
remote = remote_get(dest);
if (!remote) {
......
......@@ -96,12 +96,13 @@ static int show_tree(const unsigned char *sha1, struct strbuf *base,
if (!strcmp(type, blob_type)) {
unsigned long size;
if (sha1_object_info(sha1, &size) == OBJ_BAD)
strcpy(size_text, "BAD");
xsnprintf(size_text, sizeof(size_text),
"BAD");
else
snprintf(size_text, sizeof(size_text),
"%lu", size);
xsnprintf(size_text, sizeof(size_text),
"%lu", size);
} else