summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: ad1ed5e)
raw | patch | inline | side by side (parent: ad1ed5e)
author | Shawn Pearce <spearce@spearce.org> | |
Sat, 2 Sep 2006 04:16:31 +0000 (00:16 -0400) | ||
committer | Junio C Hamano <junkio@cox.net> | |
Sat, 2 Sep 2006 10:24:37 +0000 (03:24 -0700) |
Like xmalloc and xrealloc xstrdup dies with a useful message if
the native strdup() implementation returns NULL rather than a
valid pointer.
I just tried to use xstrdup in new code and found it to be missing.
However I expected it to be present as xmalloc and xrealloc are
already commonly used throughout the code.
[jc: removed the part that deals with last_XXX, which I am
finding more and more dubious these days.]
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
the native strdup() implementation returns NULL rather than a
valid pointer.
I just tried to use xstrdup in new code and found it to be missing.
However I expected it to be present as xmalloc and xrealloc are
already commonly used throughout the code.
[jc: removed the part that deals with last_XXX, which I am
finding more and more dubious these days.]
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Junio C Hamano <junkio@cox.net>
34 files changed:
index 8968046b0045633e6046c3126978819e9910a5f2..8cfd5d94c777770a2019e058f1140ecd5a5c9aa2 100644 (file)
--- a/blame.c
+++ b/blame.c
if (new_name) {
struct util_info* putil = get_util(p);
if (!putil->pathname)
- putil->pathname = strdup(new_name);
+ putil->pathname = xstrdup(new_name);
} else {
*pp = parent->next;
continue;
diff --git a/builtin-apply.c b/builtin-apply.c
index 1a1deaf78c61547a53bf0c3f7f1e7f37464610c5..872c8005a27c0085d47680a8e638b8cf6f3d70a3 100644 (file)
--- a/builtin-apply.c
+++ b/builtin-apply.c
static int git_apply_config(const char *var, const char *value)
{
if (!strcmp(var, "apply.whitespace")) {
- apply_default_whitespace = strdup(value);
+ apply_default_whitespace = xstrdup(value);
return 0;
}
return git_default_config(var, value);
index 432963db9006c404d4b79c7e9b5c8d539e783605..c407c033e7d4f43818d62691688911de71a5cf11 100644 (file)
--- a/builtin-fmt-merge-msg.c
+++ b/builtin-fmt-merge-msg.c
i = find_in_list(&srcs, src);
if (i < 0) {
i = srcs.nr;
- append_to_list(&srcs, strdup(src),
+ append_to_list(&srcs, xstrdup(src),
xcalloc(1, sizeof(struct src_data)));
}
src_data = srcs.payload[i];
if (pulling_head) {
- origin = strdup(src);
+ origin = xstrdup(src);
src_data->head_status |= 1;
} else if (!strncmp(line, "branch ", 7)) {
- origin = strdup(line + 7);
+ origin = xstrdup(line + 7);
append_to_list(&src_data->branch, origin, NULL);
src_data->head_status |= 2;
} else if (!strncmp(line, "tag ", 4)) {
origin = line;
- append_to_list(&src_data->tag, strdup(origin + 4), NULL);
+ append_to_list(&src_data->tag, xstrdup(origin + 4), NULL);
src_data->head_status |= 2;
} else if (!strncmp(line, "remote branch ", 14)) {
- origin = strdup(line + 14);
+ origin = xstrdup(line + 14);
append_to_list(&src_data->r_branch, origin, NULL);
src_data->head_status |= 2;
} else {
- origin = strdup(src);
- append_to_list(&src_data->generic, strdup(line), NULL);
+ origin = xstrdup(src);
+ append_to_list(&src_data->generic, xstrdup(line), NULL);
src_data->head_status |= 2;
}
new_origin[len - 2] = 0;
origin = new_origin;
} else
- origin = strdup(origin);
+ origin = xstrdup(origin);
} else {
char *new_origin = xmalloc(strlen(origin) + strlen(src) + 5);
sprintf(new_origin, "%s of %s", origin, src);
bol = strstr(commit->buffer, "\n\n");
if (!bol) {
- append_to_list(&subjects, strdup(sha1_to_hex(
+ append_to_list(&subjects, xstrdup(sha1_to_hex(
commit->object.sha1)),
NULL);
continue;
memcpy(oneline, bol, len);
oneline[len] = 0;
} else
- oneline = strdup(bol);
+ oneline = xstrdup(bol);
append_to_list(&subjects, oneline, NULL);
}
usage(fmt_merge_msg_usage);
/* get current branch */
- head = strdup(git_path("HEAD"));
+ head = xstrdup(git_path("HEAD"));
current_branch = resolve_ref(head, head_sha1, 1);
current_branch += strlen(head) - 4;
free((char *)head);
diff --git a/builtin-grep.c b/builtin-grep.c
index 8213ce240232a1dc8a0a498972323a33e8fcb7a0..6430f6d79ed58afa810a2643a13700be6579aee5 100644 (file)
--- a/builtin-grep.c
+++ b/builtin-grep.c
/* ignore empty line like grep does */
if (!buf[0])
continue;
- add_pattern(&opt, strdup(buf), argv[1], ++lno,
+ add_pattern(&opt, xstrdup(buf), argv[1], ++lno,
GREP_PATTERN);
}
fclose(patterns);
diff --git a/builtin-name-rev.c b/builtin-name-rev.c
index d44e782c999eeaf59ec661047eb95544a29dc072..52886b69b068eca899bea574c5d9790395eeb006 100644 (file)
--- a/builtin-name-rev.c
+++ b/builtin-name-rev.c
else if (!strncmp(path, "refs/", 5))
path = path + 5;
- name_rev(commit, strdup(path), 0, 0, deref);
+ name_rev(commit, xstrdup(path), 0, 0, deref);
}
return 0;
}
diff --git a/builtin-prune.c b/builtin-prune.c
index fc885ce55bbb3a44367b8cec1ea66b1918c78f15..6228c7907b183fb686c9f4cc54347c3dc16f3ec4 100644 (file)
--- a/builtin-prune.c
+++ b/builtin-prune.c
obj->flags |= SEEN;
if (parse_tree(tree) < 0)
die("bad tree object %s", sha1_to_hex(obj->sha1));
- name = strdup(name);
+ name = xstrdup(name);
add_object(obj, p, path, name);
me.up = path;
me.elem = name;
diff --git a/builtin-push.c b/builtin-push.c
index ada8338cc1d0fbf389cd346b5134595afaaa2e66..c43f2566d519ddb238ca70065ba901881dce372b 100644 (file)
--- a/builtin-push.c
+++ b/builtin-push.c
ref += 5;
if (!strncmp(ref, "tags/", 5))
- add_refspec(strdup(ref));
+ add_refspec(xstrdup(ref));
return 0;
}
if (!is_refspec) {
if (n < MAX_URI)
- uri[n++] = strdup(s);
+ uri[n++] = xstrdup(s);
else
error("more than %d URL's specified, ignoring the rest", MAX_URI);
}
else if (is_refspec && !has_explicit_refspec)
- add_refspec(strdup(s));
+ add_refspec(xstrdup(s));
}
fclose(f);
if (!n)
!strncmp(key + 7, config_repo, config_repo_len)) {
if (!strcmp(key + 7 + config_repo_len, ".url")) {
if (config_current_uri < MAX_URI)
- config_uri[config_current_uri++] = strdup(value);
+ config_uri[config_current_uri++] = xstrdup(value);
else
error("more than %d URL's specified, ignoring the rest", MAX_URI);
}
else if (config_get_refspecs &&
!strcmp(key + 7 + config_repo_len, ".push"))
- add_refspec(strdup(value));
+ add_refspec(xstrdup(value));
}
return 0;
}
diff --git a/builtin-repo-config.c b/builtin-repo-config.c
index a1756c85803f9444fd6154511640d9b3b0da07e7..9cf12d32e5bc0be8034b16551336afee1e7d3a00 100644 (file)
--- a/builtin-repo-config.c
+++ b/builtin-repo-config.c
const char *home = getenv("HOME");
local = getenv("GIT_CONFIG_LOCAL");
if (!local)
- local = repo_config = strdup(git_path("config"));
+ local = repo_config = xstrdup(git_path("config"));
if (home)
- global = strdup(mkpath("%s/.gitconfig", home));
+ global = xstrdup(mkpath("%s/.gitconfig", home));
}
- key = strdup(key_);
+ key = xstrdup(key_);
for (tl=key+strlen(key)-1; tl >= key && *tl != '.'; --tl)
*tl = tolower(*tl);
for (tl=key; *tl && *tl != '.'; ++tl)
diff --git a/builtin-rev-list.c b/builtin-rev-list.c
index 402af8e1b5516143c5f4e2303abf05d2812c5a1c..8437454fbe4e3237aaa6aaecefe54caefb621f1b 100644 (file)
--- a/builtin-rev-list.c
+++ b/builtin-rev-list.c
if (obj->flags & (UNINTERESTING | SEEN))
return;
obj->flags |= SEEN;
- name = strdup(name);
+ name = xstrdup(name);
add_object(obj, p, path, name);
}
if (parse_tree(tree) < 0)
die("bad tree object %s", sha1_to_hex(obj->sha1));
obj->flags |= SEEN;
- name = strdup(name);
+ name = xstrdup(name);
add_object(obj, p, path, name);
me.up = path;
me.elem = name;
diff --git a/builtin-rm.c b/builtin-rm.c
index 593d86744c41a1f28258b3adb6e6cd556a64b61f..33d04bd015e43965a1bc44bb281908298f152f6c 100644 (file)
--- a/builtin-rm.c
+++ b/builtin-rm.c
ret = unlink(name);
if (!ret && (slash = strrchr(name, '/'))) {
- char *n = strdup(name);
+ char *n = xstrdup(name);
do {
n[slash - name] = 0;
name = n;
diff --git a/builtin-show-branch.c b/builtin-show-branch.c
index d7de18ec0b0ace327616f2bde6ab5cdefad8dd04..578c9fafd022ce8a8676d348120c2fc7b2b1c5dd 100644 (file)
--- a/builtin-show-branch.c
+++ b/builtin-show-branch.c
en += sprintf(en, "^");
else
en += sprintf(en, "^%d", nth);
- name_commit(p, strdup(newname), 0);
+ name_commit(p, xstrdup(newname), 0);
i++;
name_first_parent_chain(p);
}
refname, MAX_REVS);
return 0;
}
- ref_name[ref_name_cnt++] = strdup(refname);
+ ref_name[ref_name_cnt++] = xstrdup(refname);
ref_name[ref_name_cnt] = NULL;
return 0;
}
default_alloc = default_alloc * 3 / 2 + 20;
default_arg = xrealloc(default_arg, sizeof *default_arg * default_alloc);
}
- default_arg[default_num++] = strdup(value);
+ default_arg[default_num++] = xstrdup(value);
default_arg[default_num] = NULL;
return 0;
}
diff --git a/builtin-symbolic-ref.c b/builtin-symbolic-ref.c
index b4ec6f28ed8903ec160ce0747fd1916f69bbacdc..1d3a5e229ae1a16211671e7591a7544af98721f8 100644 (file)
--- a/builtin-symbolic-ref.c
+++ b/builtin-symbolic-ref.c
static void check_symref(const char *HEAD)
{
unsigned char sha1[20];
- const char *git_HEAD = strdup(git_path("%s", HEAD));
+ const char *git_HEAD = xstrdup(git_path("%s", HEAD));
const char *git_refs_heads_master = resolve_ref(git_HEAD, sha1, 0);
if (git_refs_heads_master) {
/* we want to strip the .git/ part */
check_symref(argv[1]);
break;
case 3:
- create_symref(strdup(git_path("%s", argv[1])), argv[2]);
+ create_symref(xstrdup(git_path("%s", argv[1])), argv[2]);
break;
default:
usage(git_symbolic_ref_usage);
diff --git a/builtin-tar-tree.c b/builtin-tar-tree.c
index 61a413590d74d0fb167d715aa754df1a8794c085..fa666f78c5b5e44617495abb2716eded8407626c 100644 (file)
--- a/builtin-tar-tree.c
+++ b/builtin-tar-tree.c
usage(tar_tree_usage);
/* --remote=<repo> */
- url = strdup(argv[1]+9);
+ url = xstrdup(argv[1]+9);
pid = git_connect(fd, url, exec);
if (pid < 0)
return 1;
diff --git a/builtin-upload-tar.c b/builtin-upload-tar.c
index 7b401bbb779ea0cc8bca3720eab612af2b50a4c3..06a945a4b16b1b604847527fbac3aca3c7fa3a73 100644 (file)
--- a/builtin-upload-tar.c
+++ b/builtin-upload-tar.c
return nak("expected (optional) base");
if (buf[len-1] == '\n')
buf[--len] = 0;
- base = strdup(buf + 5);
+ base = xstrdup(buf + 5);
len = packet_read_line(0, buf, sizeof(buf));
}
if (len)
diff --git a/builtin-zip-tree.c b/builtin-zip-tree.c
index a5b834d360ad20223b52cc3ef2eb5848f5bbdc72..1c1f6830c1a8b9303eec3b1c11cfb1805d3049e4 100644 (file)
--- a/builtin-zip-tree.c
+++ b/builtin-zip-tree.c
switch (argc) {
case 3:
- base = strdup(argv[2]);
+ base = xstrdup(argv[2]);
baselen = strlen(base);
break;
case 2:
- base = strdup("");
+ base = xstrdup("");
baselen = 0;
break;
default:
diff --git a/config.c b/config.c
index c0897cc8076cfa62cd7e5b41513ae33c28e53dde..e8f0caf7cf674ff44b23e0182420988e9672cc69 100644 (file)
--- a/config.c
+++ b/config.c
home = getenv("HOME");
filename = getenv("GIT_CONFIG_LOCAL");
if (!filename)
- filename = repo_config = strdup(git_path("config"));
+ filename = repo_config = xstrdup(git_path("config"));
}
if (home) {
- char *user_config = strdup(mkpath("%s/.gitconfig", home));
+ char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
if (!access(user_config, R_OK))
ret = git_config_from_file(fn, user_config);
free(user_config);
if (!config_filename)
config_filename = git_path("config");
}
- config_filename = strdup(config_filename);
- lock_file = strdup(mkpath("%s.lock", config_filename));
+ config_filename = xstrdup(config_filename);
+ lock_file = xstrdup(mkpath("%s.lock", config_filename));
/*
* Since "key" actually contains the section name and the real
diff --git a/connect.c b/connect.c
index e501ccce259e7ac1a4e92fecc713950e82d3b71a..06ef387649e0645b934f3294df8b843aa328393f 100644 (file)
--- a/connect.c
+++ b/connect.c
if (len != name_len + 41) {
if (server_capabilities)
free(server_capabilities);
- server_capabilities = strdup(name + name_len + 1);
+ server_capabilities = xstrdup(name + name_len + 1);
}
if (!check_ref(name, name_len, flags))
if (path[1] == '~')
path++;
else {
- path = strdup(ptr);
+ path = xstrdup(ptr);
free_path = 1;
}
/* These underlying connection commands die() if they
* cannot connect.
*/
- char *target_host = strdup(host);
+ char *target_host = xstrdup(host);
if (git_use_proxy(host))
git_proxy_connect(fd, host);
else
index 70699fd8c48754215934a8ed45db336b9db68918..9dcbda3117a5b225aa5ee0f077b03cf8e859228b 100644 (file)
--- a/diff.c
+++ b/diff.c
return NULL;
needlen = quote_c_style(str, NULL, NULL, 0);
if (!needlen)
- return strdup(str);
+ return xstrdup(str);
xp = xmalloc(needlen + 1);
quote_c_style(str, xp, NULL, 0);
return xp;
x->is_renamed = 1;
}
else
- x->name = strdup(name_a);
+ x->name = xstrdup(name_a);
return x;
}
diff --git a/environment.c b/environment.c
index 5fae9ac3056dd00beba3b9a13be99f7bb39d584e..84d870ca4eca6e202bcbec388e9a299b887f9a12 100644 (file)
--- a/environment.c
+++ b/environment.c
}
git_graft_file = getenv(GRAFT_ENVIRONMENT);
if (!git_graft_file)
- git_graft_file = strdup(git_path("info/grafts"));
+ git_graft_file = xstrdup(git_path("info/grafts"));
}
const char *get_git_dir(void)
index 7d3812c40606a6afad796826dd0937a92f71bc7a..34df8d37d7dc92f8b652c160c49f4ace6e44e19c 100644 (file)
--- a/fetch.c
+++ b/fetch.c
*target = xrealloc(*target, targets_alloc * sizeof(**target));
*write_ref = xrealloc(*write_ref, targets_alloc * sizeof(**write_ref));
}
- (*target)[targets] = strdup(tg_one);
- (*write_ref)[targets] = rf_one ? strdup(rf_one) : NULL;
+ (*target)[targets] = xstrdup(tg_one);
+ (*write_ref)[targets] = rf_one ? xstrdup(rf_one) : NULL;
targets++;
}
return targets;
diff --git a/fsck-objects.c b/fsck-objects.c
index 24286de15dbba4795b75112d3957e8974c3ceafa..4d994f3fc83d71501bbfde5159a869b4f2a38e99 100644 (file)
--- a/fsck-objects.c
+++ b/fsck-objects.c
static int fsck_head_link(void)
{
unsigned char sha1[20];
- const char *git_HEAD = strdup(git_path("HEAD"));
+ const char *git_HEAD = xstrdup(git_path("HEAD"));
const char *git_refs_heads_master = resolve_ref(git_HEAD, sha1, 1);
int pfxlen = strlen(git_HEAD) - 4; /* strip .../.git/ part */
diff --git a/git-compat-util.h b/git-compat-util.h
index 91f2b0d3f0cf9d8539e7e09adc057dc337caae21..552b8ec23a1a927208f1ed4c48d08b513d8572c5 100644 (file)
--- a/git-compat-util.h
+++ b/git-compat-util.h
extern size_t gitstrlcpy(char *, const char *, size_t);
#endif
+static inline char* xstrdup(const char *str)
+{
+ char *ret = strdup(str);
+ if (!ret)
+ die("Out of memory, strdup failed");
+ return ret;
+}
+
static inline void *xmalloc(size_t size)
{
void *ret = malloc(size);
index 05871ad42c8c20999e2dd977ea6033f38614e862..9bb21ede8fdf82c96afc1d3ccf40e738c090054c 100644 (file)
--- a/git.c
+++ b/git.c
static int git_alias_config(const char *var, const char *value)
{
if (!strncmp(var, "alias.", 6) && !strcmp(var + 6, alias_command)) {
- alias_string = strdup(value);
+ alias_string = xstrdup(value);
}
return 0;
}
diff --git a/http-fetch.c b/http-fetch.c
index 6806f3678c2878d5d2550750394a998b2c5d54db..fac17607b442c5bf1e1d21c27ae9a2b6c473358c 100644 (file)
--- a/http-fetch.c
+++ b/http-fetch.c
ls.flags = flags;
ls.repo = repo;
- ls.path = strdup(path);
+ ls.path = xstrdup(path);
ls.dentry_name = NULL;
ls.dentry_flags = 0;
ls.userData = userData;
diff --git a/http-push.c b/http-push.c
index 7814666d8df2e202c547cf05f0768bdc3830873c..670ff007beb8a5ba3043045a0b31399cd108c310 100644 (file)
--- a/http-push.c
+++ b/http-push.c
struct remote_ls_ctx ls;
ls.flags = flags;
- ls.path = strdup(path);
+ ls.path = xstrdup(path);
ls.dentry_name = NULL;
ls.dentry_flags = 0;
ls.userData = userData;
die("bad tree object %s", sha1_to_hex(obj->sha1));
obj->flags |= SEEN;
- name = strdup(name);
+ name = xstrdup(name);
p = add_one_object(obj, p);
me.up = path;
me.elem = name;
/* Set up revision info for this refspec */
commit_argc = 3;
- new_sha1_hex = strdup(sha1_to_hex(ref->new_sha1));
+ new_sha1_hex = xstrdup(sha1_to_hex(ref->new_sha1));
old_sha1_hex = NULL;
commit_argv[1] = "--objects";
commit_argv[2] = new_sha1_hex;
diff --git a/imap-send.c b/imap-send.c
index 65c71c602db022f65660b1c29f54ddd59a3b0363..8ed0f0aa6f4e4d2314d820f9e3a0b93f6e8595d5 100644 (file)
--- a/imap-send.c
+++ b/imap-send.c
* getpass() returns a pointer to a static buffer. make a copy
* for long term storage.
*/
- srvc->pass = strdup( arg );
+ srvc->pass = xstrdup( arg );
}
if (CAP(NOLOGIN)) {
fprintf( stderr, "Skipping account %s@%s, server forbids LOGIN\n", srvc->user, srvc->host );
key += sizeof imap_key - 1;
if (!strcmp( "folder", key )) {
- imap_folder = strdup( val );
+ imap_folder = xstrdup( val );
} else if (!strcmp( "host", key )) {
{
if (!strncmp( "imap:", val, 5 ))
}
if (!strncmp( "//", val, 2 ))
val += 2;
- server.host = strdup( val );
+ server.host = xstrdup( val );
}
else if (!strcmp( "user", key ))
- server.user = strdup( val );
+ server.user = xstrdup( val );
else if (!strcmp( "pass", key ))
- server.pass = strdup( val );
+ server.pass = xstrdup( val );
else if (!strcmp( "port", key ))
server.port = git_config_int( key, val );
else if (!strcmp( "tunnel", key ))
- server.tunnel = strdup( val );
+ server.tunnel = xstrdup( val );
return 0;
}
diff --git a/merge-file.c b/merge-file.c
index f32c6538250e560039de2d5262def7953915411d..fc9b148993027d4064257d4df8e63a12e1afc5d4 100644 (file)
--- a/merge-file.c
+++ b/merge-file.c
fd = mkstemp(filename);
if (fd < 0)
return NULL;
- filename = strdup(filename);
+ filename = xstrdup(filename);
if (f->size != xwrite(fd, f->ptr, f->size)) {
rm_temp_file(filename);
return NULL;
diff --git a/merge-recursive.c b/merge-recursive.c
index 48b2763de6892be60ab6be8a6e490d15e4ff81ac..611cd95cf597b0ccf06cf9b4318eb34a86a4c05a 100644 (file)
--- a/merge-recursive.c
+++ b/merge-recursive.c
static int mkdir_p(const char *path, unsigned long mode)
{
- /* path points to cache entries, so strdup before messing with it */
- char *buf = strdup(path);
+ /* path points to cache entries, so xstrdup before messing with it */
+ char *buf = xstrdup(path);
int result = safe_create_leading_directories(buf);
free(buf);
return result;
git_unpack_file(a->sha1, src1);
git_unpack_file(b->sha1, src2);
- argv[2] = la = strdup(mkpath("%s/%s", branch1, a->path));
- argv[6] = lb = strdup(mkpath("%s/%s", branch2, b->path));
- argv[4] = lo = strdup(mkpath("orig/%s", o->path));
+ argv[2] = la = xstrdup(mkpath("%s/%s", branch1, a->path));
+ argv[6] = lb = xstrdup(mkpath("%s/%s", branch2, b->path));
+ argv[4] = lo = xstrdup(mkpath("orig/%s", o->path));
argv[7] = src1;
argv[8] = orig;
argv[9] = src2,
original_index_file = getenv("GIT_INDEX_FILE");
if (!original_index_file)
- original_index_file = strdup(git_path("index"));
+ original_index_file = xstrdup(git_path("index"));
- temporary_index_file = strdup(git_path("mrg-rcrsv-tmp-idx"));
+ temporary_index_file = xstrdup(git_path("mrg-rcrsv-tmp-idx"));
if (argc < 4)
die("Usage: %s <base>... -- <head> <remote> ...\n", argv[0]);
diff --git a/merge-tree.c b/merge-tree.c
index c2e9a867edb5b843150cd3df47583f49f15314cb..60df758c41174bb8a9cc526660752c80b1988bbf 100644 (file)
--- a/merge-tree.c
+++ b/merge-tree.c
@@ -177,7 +177,7 @@ static void resolve(const char *base, struct name_entry *branch1, struct name_en
if (!branch1)
return;
- path = strdup(mkpath("%s%s", base, result->path));
+ path = xstrdup(mkpath("%s%s", base, result->path));
orig = create_entry(2, branch1->mode, branch1->sha1, path);
final = create_entry(0, result->mode, result->sha1, path);
@@ -233,7 +233,7 @@ static struct merge_list *link_entry(unsigned stage, const char *base, struct na
if (entry)
path = entry->path;
else
- path = strdup(mkpath("%s%s", base, n->path));
+ path = xstrdup(mkpath("%s%s", base, n->path));
link = create_entry(stage, n->mode, n->sha1, path);
link->link = entry;
return link;
diff --git a/path-list.c b/path-list.c
index b1ee72d1dc25085f2114748001d21e3e518e54ee..0c332dc7b556ba894f0452b0172e7dd1e485f929 100644 (file)
--- a/path-list.c
+++ b/path-list.c
(list->nr - index)
* sizeof(struct path_list_item));
list->items[index].path = list->strdup_paths ?
- strdup(path) : (char *)path;
+ xstrdup(path) : (char *)path;
list->items[index].util = NULL;
list->nr++;
index aab14fc107353099756403c1bf08a0786e184d98..5e653141ceb8183cfb7922c3ad89fd1a0110647a 100644 (file)
--- a/refs.c
+++ b/refs.c
}
lock->lk = xcalloc(1, sizeof(struct lock_file));
- lock->ref_file = strdup(path);
- lock->log_file = strdup(git_path("logs/%s", lock->ref_file + plen));
+ lock->ref_file = xstrdup(path);
+ lock->log_file = xstrdup(git_path("logs/%s", lock->ref_file + plen));
lock->force_write = lstat(lock->ref_file, &st) && errno == ENOENT;
if (safe_create_leading_directories(lock->ref_file))
diff --git a/server-info.c b/server-info.c
index 7df628f2b226f6984d168af0382680b9dae0751a..2fb8f571033918b870cde35979b377c98b9845b5 100644 (file)
--- a/server-info.c
+++ b/server-info.c
static int update_info_refs(int force)
{
- char *path0 = strdup(git_path("info/refs"));
+ char *path0 = xstrdup(git_path("info/refs"));
int len = strlen(path0);
char *path1 = xmalloc(len + 2);
diff --git a/sha1_file.c b/sha1_file.c
index 76f66e6a85c8f1327822708c5515ed6c28d508b6..4ef98053f8b5ba9988fd28afc60a1ae2fced93c9 100644 (file)
--- a/sha1_file.c
+++ b/sha1_file.c
/*
* NOTE! This returns a statically allocated buffer, so you have to be
- * careful about using it. Do a "strdup()" if you need to save the
+ * careful about using it. Do a "xstrdup()" if you need to save the
* filename.
*
* Also note that this returns the location for creating. Reading
diff --git a/sha1_name.c b/sha1_name.c
index 3f6b77ccfadab14453a76b6654b50b186c9f5b25..1fbc4438059b68f31aa25fb8e3b82b37a4d02819 100644 (file)
--- a/sha1_name.c
+++ b/sha1_name.c
pathname = resolve_ref(git_path(*p, len, str), this_result, 1);
if (pathname) {
if (!refs_found++)
- real_path = strdup(pathname);
+ real_path = xstrdup(pathname);
if (!warn_ambiguous_refs)
break;
}