Replace uses of strdup with xstrdup.
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>
Shawn Pearce committed
Sep 2, 2006 at 00:16 UTC
9befac470b4cfad529032dbcffcb71242ec71f91
34 files changed
+84
-76
blame.c
+1
-1
@@ -617,7 +617,7 @@ static void simplify_commit(struct rev_info *revs, struct commit *commit)
617
if (new_name) {
618
struct util_info* putil = get_util(p);
619
if (!putil->pathname)
620
- putil->pathname = strdup(new_name);
620
+ putil->pathname = xstrdup(new_name);
621
} else {
622
*pp = parent->next;
623
continue;
builtin-apply.c
+1
-1
@@ -2449,7 +2449,7 @@ static int apply_patch(int fd, const char *filename, int inaccurate_eof)
2449
static int git_apply_config(const char *var, const char *value)
2450
{
2451
if (!strcmp(var, "apply.whitespace")) {
2452
- apply_default_whitespace = strdup(value);
2452
+ apply_default_whitespace = xstrdup(value);
2453
return 0;
2454
}
2455
return git_default_config(var, value);
builtin-fmt-merge-msg.c
+11
-11
@@ -111,29 +111,29 @@ static int handle_line(char *line)
111
i = find_in_list(&srcs, src);
112
if (i < 0) {
113
i = srcs.nr;
114
- append_to_list(&srcs, strdup(src),
114
+ append_to_list(&srcs, xstrdup(src),
115
xcalloc(1, sizeof(struct src_data)));
116
}
117
src_data = srcs.payload[i];
118
119
if (pulling_head) {
120
- origin = strdup(src);
120
+ origin = xstrdup(src);
121
src_data->head_status |= 1;
122
} else if (!strncmp(line, "branch ", 7)) {
123
- origin = strdup(line + 7);
123
+ origin = xstrdup(line + 7);
124
append_to_list(&src_data->branch, origin, NULL);
125
src_data->head_status |= 2;
126
} else if (!strncmp(line, "tag ", 4)) {
127
origin = line;
128
- append_to_list(&src_data->tag, strdup(origin + 4), NULL);
128
+ append_to_list(&src_data->tag, xstrdup(origin + 4), NULL);
129
src_data->head_status |= 2;
130
} else if (!strncmp(line, "remote branch ", 14)) {
131
- origin = strdup(line + 14);
131
+ origin = xstrdup(line + 14);
132
append_to_list(&src_data->r_branch, origin, NULL);
133
src_data->head_status |= 2;
134
} else {
135
- origin = strdup(src);
136
- append_to_list(&src_data->generic, strdup(line), NULL);
135
+ origin = xstrdup(src);
136
+ append_to_list(&src_data->generic, xstrdup(line), NULL);
137
src_data->head_status |= 2;
138
}
139
@@ -145,7 +145,7 @@ static int handle_line(char *line)
145
new_origin[len - 2] = 0;
146
origin = new_origin;
147
} else
148
- origin = strdup(origin);
148
+ origin = xstrdup(origin);
149
} else {
150
char *new_origin = xmalloc(strlen(origin) + strlen(src) + 5);
151
sprintf(new_origin, "%s of %s", origin, src);
@@ -203,7 +203,7 @@ static void shortlog(const char *name, unsigned char *sha1,
203
204
bol = strstr(commit->buffer, "\n\n");
205
if (!bol) {
206
- append_to_list(&subjects, strdup(sha1_to_hex(
206
+ append_to_list(&subjects, xstrdup(sha1_to_hex(
207
commit->object.sha1)),
208
NULL);
209
continue;
@@ -218,7 +218,7 @@ static void shortlog(const char *name, unsigned char *sha1,
218
memcpy(oneline, bol, len);
219
oneline[len] = 0;
220
} else
221
- oneline = strdup(bol);
221
+ oneline = xstrdup(bol);
222
append_to_list(&subjects, oneline, NULL);
223
}
224
@@ -277,7 +277,7 @@ int cmd_fmt_merge_msg(int argc, const char **argv, const char *prefix)
277
usage(fmt_merge_msg_usage);
278
279
/* get current branch */
280
- head = strdup(git_path("HEAD"));
280
+ head = xstrdup(git_path("HEAD"));
281
current_branch = resolve_ref(head, head_sha1, 1);
282
current_branch += strlen(head) - 4;
283
free((char *)head);
builtin-grep.c
+1
-1
@@ -1048,7 +1048,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
1048
/* ignore empty line like grep does */
1049
if (!buf[0])
1050
continue;
1051
- add_pattern(&opt, strdup(buf), argv[1], ++lno,
1051
+ add_pattern(&opt, xstrdup(buf), argv[1], ++lno,
1052
GREP_PATTERN);
1053
}
1054
fclose(patterns);
builtin-name-rev.c
+1
-1
@@ -100,7 +100,7 @@ static int name_ref(const char *path, const unsigned char *sha1)
100
else if (!strncmp(path, "refs/", 5))
101
path = path + 5;
102
103
- name_rev(commit, strdup(path), 0, 0, deref);
103
+ name_rev(commit, xstrdup(path), 0, 0, deref);
104
}
105
return 0;
106
}
builtin-prune.c
+1
-1
@@ -106,7 +106,7 @@ static void process_tree(struct tree *tree,
106
obj->flags |= SEEN;
107
if (parse_tree(tree) < 0)
108
die("bad tree object %s", sha1_to_hex(obj->sha1));
109
- name = strdup(name);
109
+ name = xstrdup(name);
110
add_object(obj, p, path, name);
111
me.up = path;
112
me.elem = name;
builtin-push.c
+5
-5
@@ -33,7 +33,7 @@ static int expand_one_ref(const char *ref, const unsigned char *sha1)
33
ref += 5;
34
35
if (!strncmp(ref, "tags/", 5))
36
- add_refspec(strdup(ref));
36
+ add_refspec(xstrdup(ref));
37
return 0;
38
}
39
@@ -100,12 +100,12 @@ static int get_remotes_uri(const char *repo, const char *uri[MAX_URI])
100
101
if (!is_refspec) {
102
if (n < MAX_URI)
103
- uri[n++] = strdup(s);
103
+ uri[n++] = xstrdup(s);
104
else
105
error("more than %d URL's specified, ignoring the rest", MAX_URI);
106
}
107
else if (is_refspec && !has_explicit_refspec)
108
- add_refspec(strdup(s));
108
+ add_refspec(xstrdup(s));
109
}
110
fclose(f);
111
if (!n)
@@ -125,13 +125,13 @@ static int get_remote_config(const char* key, const char* value)
125
!strncmp(key + 7, config_repo, config_repo_len)) {
126
if (!strcmp(key + 7 + config_repo_len, ".url")) {
127
if (config_current_uri < MAX_URI)
128
- config_uri[config_current_uri++] = strdup(value);
128
+ config_uri[config_current_uri++] = xstrdup(value);
129
else
130
error("more than %d URL's specified, ignoring the rest", MAX_URI);
131
}
132
else if (config_get_refspecs &&
133
!strcmp(key + 7 + config_repo_len, ".push"))
134
- add_refspec(strdup(value));
134
+ add_refspec(xstrdup(value));
135
}
136
return 0;
137
}
builtin-repo-config.c
+3
-3
@@ -72,12 +72,12 @@ static int get_value(const char* key_, const char* regex_)
72
const char *home = getenv("HOME");
73
local = getenv("GIT_CONFIG_LOCAL");
74
if (!local)
75
- local = repo_config = strdup(git_path("config"));
75
+ local = repo_config = xstrdup(git_path("config"));
76
if (home)
77
- global = strdup(mkpath("%s/.gitconfig", home));
77
+ global = xstrdup(mkpath("%s/.gitconfig", home));
78
}
79
80
- key = strdup(key_);
80
+ key = xstrdup(key_);
81
for (tl=key+strlen(key)-1; tl >= key && *tl != '.'; --tl)
82
*tl = tolower(*tl);
83
for (tl=key; *tl && *tl != '.'; ++tl)
builtin-rev-list.c
+2
-2
@@ -109,7 +109,7 @@ static void process_blob(struct blob *blob,
109
if (obj->flags & (UNINTERESTING | SEEN))
110
return;
111
obj->flags |= SEEN;
112
- name = strdup(name);
112
+ name = xstrdup(name);
113
add_object(obj, p, path, name);
114
}
115
@@ -130,7 +130,7 @@ static void process_tree(struct tree *tree,
130
if (parse_tree(tree) < 0)
131
die("bad tree object %s", sha1_to_hex(obj->sha1));
132
obj->flags |= SEEN;
133
- name = strdup(name);
133
+ name = xstrdup(name);
134
add_object(obj, p, path, name);
135
me.up = path;
136
me.elem = name;
builtin-rm.c
+1
-1
@@ -32,7 +32,7 @@ static int remove_file(const char *name)
32
33
ret = unlink(name);
34
if (!ret && (slash = strrchr(name, '/'))) {
35
- char *n = strdup(name);
35
+ char *n = xstrdup(name);
36
do {
37
n[slash - name] = 0;
38
name = n;
builtin-show-branch.c
+3
-3
@@ -163,7 +163,7 @@ static void name_commits(struct commit_list *list,
163
en += sprintf(en, "^");
164
else
165
en += sprintf(en, "^%d", nth);
166
- name_commit(p, strdup(newname), 0);
166
+ name_commit(p, xstrdup(newname), 0);
167
i++;
168
name_first_parent_chain(p);
169
}
@@ -364,7 +364,7 @@ static int append_ref(const char *refname, const unsigned char *sha1)
364
refname, MAX_REVS);
365
return 0;
366
}
367
- ref_name[ref_name_cnt++] = strdup(refname);
367
+ ref_name[ref_name_cnt++] = xstrdup(refname);
368
ref_name[ref_name_cnt] = NULL;
369
return 0;
370
}
@@ -521,7 +521,7 @@ static int git_show_branch_config(const char *var, const char *value)
521
default_alloc = default_alloc * 3 / 2 + 20;
522
default_arg = xrealloc(default_arg, sizeof *default_arg * default_alloc);
523
}
524
- default_arg[default_num++] = strdup(value);
524
+ default_arg[default_num++] = xstrdup(value);
525
default_arg[default_num] = NULL;
526
return 0;
527
}
builtin-symbolic-ref.c
+2
-2
@@ -7,7 +7,7 @@ static const char git_symbolic_ref_usage[] =
7
static void check_symref(const char *HEAD)
8
{
9
unsigned char sha1[20];
10
- const char *git_HEAD = strdup(git_path("%s", HEAD));
10
+ const char *git_HEAD = xstrdup(git_path("%s", HEAD));
11
const char *git_refs_heads_master = resolve_ref(git_HEAD, sha1, 0);
12
if (git_refs_heads_master) {
13
/* we want to strip the .git/ part */
@@ -26,7 +26,7 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
26
check_symref(argv[1]);
27
break;
28
case 3:
29
- create_symref(strdup(git_path("%s", argv[1])), argv[2]);
29
+ create_symref(xstrdup(git_path("%s", argv[1])), argv[2]);
30
break;
31
default:
32
usage(git_symbolic_ref_usage);
builtin-tar-tree.c
+1
-1
@@ -351,7 +351,7 @@ static int remote_tar(int argc, const char **argv)
351
usage(tar_tree_usage);
352
353
/* --remote=<repo> */
354
- url = strdup(argv[1]+9);
354
+ url = xstrdup(argv[1]+9);
355
pid = git_connect(fd, url, exec);
356
if (pid < 0)
357
return 1;
builtin-upload-tar.c
+1
-1
@@ -53,7 +53,7 @@ int cmd_upload_tar(int argc, const char **argv, const char *prefix)
53
return nak("expected (optional) base");
54
if (buf[len-1] == '\n')
55
buf[--len] = 0;
56
- base = strdup(buf + 5);
56
+ base = xstrdup(buf + 5);
57
len = packet_read_line(0, buf, sizeof(buf));
58
}
59
if (len)
builtin-zip-tree.c
+2
-2
@@ -311,11 +311,11 @@ int cmd_zip_tree(int argc, const char **argv, const char *prefix)
311
312
switch (argc) {
313
case 3:
314
- base = strdup(argv[2]);
314
+ base = xstrdup(argv[2]);
315
baselen = strlen(base);
316
break;
317
case 2:
318
- base = strdup("");
318
+ base = xstrdup("");
319
baselen = 0;
320
break;
321
default:
config.c
+4
-4
@@ -350,11 +350,11 @@ int git_config(config_fn_t fn)
350
home = getenv("HOME");
351
filename = getenv("GIT_CONFIG_LOCAL");
352
if (!filename)
353
- filename = repo_config = strdup(git_path("config"));
353
+ filename = repo_config = xstrdup(git_path("config"));
354
}
355
356
if (home) {
357
- char *user_config = strdup(mkpath("%s/.gitconfig", home));
357
+ char *user_config = xstrdup(mkpath("%s/.gitconfig", home));
358
if (!access(user_config, R_OK))
359
ret = git_config_from_file(fn, user_config);
360
free(user_config);
@@ -545,8 +545,8 @@ int git_config_set_multivar(const char* key, const char* value,
545
if (!config_filename)
546
config_filename = git_path("config");
547
}
548
- config_filename = strdup(config_filename);
549
- lock_file = strdup(mkpath("%s.lock", config_filename));
548
+ config_filename = xstrdup(config_filename);
549
+ lock_file = xstrdup(mkpath("%s.lock", config_filename));
550
551
/*
552
* Since "key" actually contains the section name and the real
connect.c
+3
-3
@@ -69,7 +69,7 @@ struct ref **get_remote_heads(int in, struct ref **list,
69
if (len != name_len + 41) {
70
if (server_capabilities)
71
free(server_capabilities);
72
- server_capabilities = strdup(name + name_len + 1);
72
+ server_capabilities = xstrdup(name + name_len + 1);
73
}
74
75
if (!check_ref(name, name_len, flags))
@@ -661,7 +661,7 @@ int git_connect(int fd[2], char *url, const char *prog)
661
if (path[1] == '~')
662
path++;
663
else {
664
- path = strdup(ptr);
664
+ path = xstrdup(ptr);
665
free_path = 1;
666
}
667
@@ -672,7 +672,7 @@ int git_connect(int fd[2], char *url, const char *prog)
672
/* These underlying connection commands die() if they
673
* cannot connect.
674
*/
675
- char *target_host = strdup(host);
675
+ char *target_host = xstrdup(host);
676
if (git_use_proxy(host))
677
git_proxy_connect(fd, host);
678
else
diff.c
+2
-2
@@ -216,7 +216,7 @@ static char *quote_one(const char *str)
216
return NULL;
217
needlen = quote_c_style(str, NULL, NULL, 0);
218
if (!needlen)
219
- return strdup(str);
219
+ return xstrdup(str);
220
xp = xmalloc(needlen + 1);
221
quote_c_style(str, xp, NULL, 0);
222
return xp;
@@ -658,7 +658,7 @@ static struct diffstat_file *diffstat_add(struct diffstat_t *diffstat,
658
x->is_renamed = 1;
659
}
660
else
661
- x->name = strdup(name_a);
661
+ x->name = xstrdup(name_a);
662
return x;
663
}
664
environment.c
+1
-1
@@ -47,7 +47,7 @@ static void setup_git_env(void)
47
}
48
git_graft_file = getenv(GRAFT_ENVIRONMENT);
49
if (!git_graft_file)
50
- git_graft_file = strdup(git_path("info/grafts"));
50
+ git_graft_file = xstrdup(git_path("info/grafts"));
51
}
52
53
const char *get_git_dir(void)
fetch.c
+2
-2
@@ -234,8 +234,8 @@ int pull_targets_stdin(char ***target, const char ***write_ref)
234
*target = xrealloc(*target, targets_alloc * sizeof(**target));
235
*write_ref = xrealloc(*write_ref, targets_alloc * sizeof(**write_ref));
236
}
237
- (*target)[targets] = strdup(tg_one);
238
- (*write_ref)[targets] = rf_one ? strdup(rf_one) : NULL;
237
+ (*target)[targets] = xstrdup(tg_one);
238
+ (*write_ref)[targets] = rf_one ? xstrdup(rf_one) : NULL;
239
targets++;
240
}
241
return targets;
fsck-objects.c
+1
-1
@@ -458,7 +458,7 @@ static void fsck_object_dir(const char *path)
458
static int fsck_head_link(void)
459
{
460
unsigned char sha1[20];
461
- const char *git_HEAD = strdup(git_path("HEAD"));
461
+ const char *git_HEAD = xstrdup(git_path("HEAD"));
462
const char *git_refs_heads_master = resolve_ref(git_HEAD, sha1, 1);
463
int pfxlen = strlen(git_HEAD) - 4; /* strip .../.git/ part */
464
git-compat-util.h
+8
@@ -84,6 +84,14 @@ extern char *gitstrcasestr(const char *haystack, const char *needle);
84
extern size_t gitstrlcpy(char *, const char *, size_t);
85
#endif
86
87
+static inline char* xstrdup(const char *str)
88
+{
89
+ char *ret = strdup(str);
90
+ if (!ret)
91
+ die("Out of memory, strdup failed");
92
+ return ret;
93
+}
94
+
95
static inline void *xmalloc(size_t size)
96
{
97
void *ret = malloc(size);
git.c
+1
-1
@@ -97,7 +97,7 @@ static char *alias_string;
97
static int git_alias_config(const char *var, const char *value)
98
{
99
if (!strncmp(var, "alias.", 6) && !strcmp(var + 6, alias_command)) {
100
- alias_string = strdup(value);
100
+ alias_string = xstrdup(value);
101
}
102
return 0;
103
}
http-fetch.c
+1
-1
@@ -787,7 +787,7 @@ static int remote_ls(struct alt_base *repo, const char *path, int flags,
787
788
ls.flags = flags;
789
ls.repo = repo;
790
- ls.path = strdup(path);
790
+ ls.path = xstrdup(path);
791
ls.dentry_name = NULL;
792
ls.dentry_flags = 0;
793
ls.userData = userData;
http-push.c
+3
-3
@@ -1539,7 +1539,7 @@ static void remote_ls(const char *path, int flags,
1539
struct remote_ls_ctx ls;
1540
1541
ls.flags = flags;
1542
- ls.path = strdup(path);
1542
+ ls.path = xstrdup(path);
1543
ls.dentry_name = NULL;
1544
ls.dentry_flags = 0;
1545
ls.userData = userData;
@@ -1738,7 +1738,7 @@ static struct object_list **process_tree(struct tree *tree,
1738
die("bad tree object %s", sha1_to_hex(obj->sha1));
1739
1740
obj->flags |= SEEN;
1741
- name = strdup(name);
1741
+ name = xstrdup(name);
1742
p = add_one_object(obj, p);
1743
me.up = path;
1744
me.elem = name;
@@ -2467,7 +2467,7 @@ int main(int argc, char **argv)
2467
2468
/* Set up revision info for this refspec */
2469
commit_argc = 3;
2470
- new_sha1_hex = strdup(sha1_to_hex(ref->new_sha1));
2470
+ new_sha1_hex = xstrdup(sha1_to_hex(ref->new_sha1));
2471
old_sha1_hex = NULL;
2472
commit_argv[1] = "--objects";
2473
commit_argv[2] = new_sha1_hex;
imap-send.c
+6
-6
@@ -1032,7 +1032,7 @@ imap_open_store( imap_server_conf_t *srvc )
1032
* getpass() returns a pointer to a static buffer. make a copy
1033
* for long term storage.
1034
*/
1035
- srvc->pass = strdup( arg );
1035
+ srvc->pass = xstrdup( arg );
1036
}
1037
if (CAP(NOLOGIN)) {
1038
fprintf( stderr, "Skipping account %s@%s, server forbids LOGIN\n", srvc->user, srvc->host );
@@ -1288,7 +1288,7 @@ git_imap_config(const char *key, const char *val)
1288
key += sizeof imap_key - 1;
1289
1290
if (!strcmp( "folder", key )) {
1291
- imap_folder = strdup( val );
1291
+ imap_folder = xstrdup( val );
1292
} else if (!strcmp( "host", key )) {
1293
{
1294
if (!strncmp( "imap:", val, 5 ))
@@ -1298,16 +1298,16 @@ git_imap_config(const char *key, const char *val)
1298
}
1299
if (!strncmp( "//", val, 2 ))
1300
val += 2;
1301
- server.host = strdup( val );
1301
+ server.host = xstrdup( val );
1302
}
1303
else if (!strcmp( "user", key ))
1304
- server.user = strdup( val );
1304
+ server.user = xstrdup( val );
1305
else if (!strcmp( "pass", key ))
1306
- server.pass = strdup( val );
1306
+ server.pass = xstrdup( val );
1307
else if (!strcmp( "port", key ))
1308
server.port = git_config_int( key, val );
1309
else if (!strcmp( "tunnel", key ))
1310
- server.tunnel = strdup( val );
1310
+ server.tunnel = xstrdup( val );
1311
return 0;
1312
}
1313
merge-file.c
+1
-1
@@ -21,7 +21,7 @@ static const char *write_temp_file(mmfile_t *f)
21
fd = mkstemp(filename);
22
if (fd < 0)
23
return NULL;
24
- filename = strdup(filename);
24
+ filename = xstrdup(filename);
25
if (f->size != xwrite(fd, f->ptr, f->size)) {
26
rm_temp_file(filename);
27
return NULL;
merge-recursive.c
+7
-7
@@ -513,8 +513,8 @@ static char *unique_path(const char *path, const char *branch)
513
514
static int mkdir_p(const char *path, unsigned long mode)
515
{
516
- /* path points to cache entries, so strdup before messing with it */
517
- char *buf = strdup(path);
516
+ /* path points to cache entries, so xstrdup before messing with it */
517
+ char *buf = xstrdup(path);
518
int result = safe_create_leading_directories(buf);
519
free(buf);
520
return result;
@@ -668,9 +668,9 @@ static struct merge_file_info merge_file(struct diff_filespec *o,
668
git_unpack_file(a->sha1, src1);
669
git_unpack_file(b->sha1, src2);
670
671
- argv[2] = la = strdup(mkpath("%s/%s", branch1, a->path));
672
- argv[6] = lb = strdup(mkpath("%s/%s", branch2, b->path));
673
- argv[4] = lo = strdup(mkpath("orig/%s", o->path));
671
+ argv[2] = la = xstrdup(mkpath("%s/%s", branch1, a->path));
672
+ argv[6] = lb = xstrdup(mkpath("%s/%s", branch2, b->path));
673
+ argv[4] = lo = xstrdup(mkpath("orig/%s", o->path));
674
argv[7] = src1;
675
argv[8] = orig;
676
argv[9] = src2,
@@ -1314,9 +1314,9 @@ int main(int argc, char *argv[])
1314
original_index_file = getenv("GIT_INDEX_FILE");
1315
1316
if (!original_index_file)
1317
- original_index_file = strdup(git_path("index"));
1317
+ original_index_file = xstrdup(git_path("index"));
1318
1319
- temporary_index_file = strdup(git_path("mrg-rcrsv-tmp-idx"));
1319
+ temporary_index_file = xstrdup(git_path("mrg-rcrsv-tmp-idx"));
1320
1321
if (argc < 4)
1322
die("Usage: %s <base>... -- <head> <remote> ...\n", argv[0]);
merge-tree.c
+2
-2
@@ -177,7 +177,7 @@ static void resolve(const char *base, struct name_entry *branch1, struct name_en
177
if (!branch1)
178
return;
179
180
- path = strdup(mkpath("%s%s", base, result->path));
180
+ path = xstrdup(mkpath("%s%s", base, result->path));
181
orig = create_entry(2, branch1->mode, branch1->sha1, path);
182
final = create_entry(0, result->mode, result->sha1, path);
183
@@ -233,7 +233,7 @@ static struct merge_list *link_entry(unsigned stage, const char *base, struct na
233
if (entry)
234
path = entry->path;
235
else
236
- path = strdup(mkpath("%s%s", base, n->path));
236
+ path = xstrdup(mkpath("%s%s", base, n->path));
237
link = create_entry(stage, n->mode, n->sha1, path);
238
link->link = entry;
239
return link;
path-list.c
+1
-1
@@ -45,7 +45,7 @@ static int add_entry(struct path_list *list, const char *path)
45
(list->nr - index)
46
* sizeof(struct path_list_item));
47
list->items[index].path = list->strdup_paths ?
48
- strdup(path) : (char *)path;
48
+ xstrdup(path) : (char *)path;
49
list->items[index].util = NULL;
50
list->nr++;
51
refs.c
+2
-2
@@ -313,8 +313,8 @@ static struct ref_lock *lock_ref_sha1_basic(const char *path,
313
}
314
lock->lk = xcalloc(1, sizeof(struct lock_file));
315
316
- lock->ref_file = strdup(path);
317
- lock->log_file = strdup(git_path("logs/%s", lock->ref_file + plen));
316
+ lock->ref_file = xstrdup(path);
317
+ lock->log_file = xstrdup(git_path("logs/%s", lock->ref_file + plen));
318
lock->force_write = lstat(lock->ref_file, &st) && errno == ENOENT;
319
320
if (safe_create_leading_directories(lock->ref_file))
server-info.c
+1
-1
@@ -23,7 +23,7 @@ static int add_info_ref(const char *path, const unsigned char *sha1)
23
24
static int update_info_refs(int force)
25
{
26
- char *path0 = strdup(git_path("info/refs"));
26
+ char *path0 = xstrdup(git_path("info/refs"));
27
int len = strlen(path0);
28
char *path1 = xmalloc(len + 2);
29
sha1_file.c
+1
-1
@@ -115,7 +115,7 @@ static void fill_sha1_path(char *pathbuf, const unsigned char *sha1)
115
116
/*
117
* NOTE! This returns a statically allocated buffer, so you have to be
118
- * careful about using it. Do a "strdup()" if you need to save the
118
+ * careful about using it. Do a "xstrdup()" if you need to save the
119
* filename.
120
*
121
* Also note that this returns the location for creating. Reading
sha1_name.c
+1
-1
@@ -279,7 +279,7 @@ static int get_sha1_basic(const char *str, int len, unsigned char *sha1)
279
pathname = resolve_ref(git_path(*p, len, str), this_result, 1);
280
if (pathname) {
281
if (!refs_found++)
282
- real_path = strdup(pathname);
282
+ real_path = xstrdup(pathname);
283
if (!warn_ambiguous_refs)
284
break;
285
}