Use xmalloc instead of malloc
Signed-off-by: Jonas Fonseca <fonseca@diku.dk> Signed-off-by: Junio C Hamano <junkio@cox.net>
Jonas Fonseca committed
Sep 1, 2006 at 00:32 UTC
2d7320d0b09d7a9aab4e5dbc5458f37bfb6ce9f5
9 files changed
+16
-16
builtin-fmt-merge-msg.c
+3
-3
@@ -140,14 +140,14 @@ static int handle_line(char *line)
140
if (!strcmp(".", src) || !strcmp(src, origin)) {
141
int len = strlen(origin);
142
if (origin[0] == '\'' && origin[len - 1] == '\'') {
143
- char *new_origin = malloc(len - 1);
143
+ char *new_origin = xmalloc(len - 1);
144
memcpy(new_origin, origin + 1, len - 2);
145
new_origin[len - 1] = 0;
146
origin = new_origin;
147
} else
148
origin = strdup(origin);
149
} else {
150
- char *new_origin = malloc(strlen(origin) + strlen(src) + 5);
150
+ char *new_origin = xmalloc(strlen(origin) + strlen(src) + 5);
151
sprintf(new_origin, "%s of %s", origin, src);
152
origin = new_origin;
153
}
@@ -214,7 +214,7 @@ static void shortlog(const char *name, unsigned char *sha1,
214
215
if (eol) {
216
int len = eol - bol;
217
- oneline = malloc(len + 1);
217
+ oneline = xmalloc(len + 1);
218
memcpy(oneline, bol, len);
219
oneline[len] = 0;
220
} else
builtin-repo-config.c
+2
-2
@@ -84,7 +84,7 @@ static int get_value(const char* key_, const char* regex_)
84
*tl = tolower(*tl);
85
86
if (use_key_regexp) {
87
- key_regexp = (regex_t*)malloc(sizeof(regex_t));
87
+ key_regexp = (regex_t*)xmalloc(sizeof(regex_t));
88
if (regcomp(key_regexp, key, REG_EXTENDED)) {
89
fprintf(stderr, "Invalid key pattern: %s\n", key_);
90
goto free_strings;
@@ -97,7 +97,7 @@ static int get_value(const char* key_, const char* regex_)
97
regex_++;
98
}
99
100
- regexp = (regex_t*)malloc(sizeof(regex_t));
100
+ regexp = (regex_t*)xmalloc(sizeof(regex_t));
101
if (regcomp(regexp, regex_, REG_EXTENDED)) {
102
fprintf(stderr, "Invalid pattern: %s\n", regex_);
103
goto free_strings;
config.c
+2
-2
@@ -565,7 +565,7 @@ int git_config_set_multivar(const char* key, const char* value,
565
/*
566
* Validate the key and while at it, lower case it for matching.
567
*/
568
- store.key = (char*)malloc(strlen(key)+1);
568
+ store.key = xmalloc(strlen(key) + 1);
569
dot = 0;
570
for (i = 0; key[i]; i++) {
571
unsigned char c = key[i];
@@ -633,7 +633,7 @@ int git_config_set_multivar(const char* key, const char* value,
633
} else
634
store.do_not_match = 0;
635
636
- store.value_regex = (regex_t*)malloc(sizeof(regex_t));
636
+ store.value_regex = (regex_t*)xmalloc(sizeof(regex_t));
637
if (regcomp(store.value_regex, value_regex,
638
REG_EXTENDED)) {
639
fprintf(stderr, "Invalid pattern: %s\n",
git.c
+1
-1
@@ -29,7 +29,7 @@ static void prepend_to_path(const char *dir, int len)
29
30
path_len = len + strlen(old_path) + 1;
31
32
- path = malloc(path_len + 1);
32
+ path = xmalloc(path_len + 1);
33
34
memcpy(path, dir, len);
35
path[len] = ':';
help.c
+1
-1
@@ -184,7 +184,7 @@ static void show_man_page(const char *git_cmd)
184
page = git_cmd;
185
else {
186
int page_len = strlen(git_cmd) + 4;
187
- char *p = malloc(page_len + 1);
187
+ char *p = xmalloc(page_len + 1);
188
strcpy(p, "git-");
189
strcpy(p + 4, git_cmd);
190
p[page_len] = 0;
merge-recursive.c
+3
-3
@@ -283,7 +283,7 @@ static int save_files_dirs(const unsigned char *sha1,
283
unsigned int mode, int stage)
284
{
285
int len = strlen(path);
286
- char *newpath = malloc(baselen + len + 1);
286
+ char *newpath = xmalloc(baselen + len + 1);
287
memcpy(newpath, base, baselen);
288
memcpy(newpath + baselen, path, len);
289
newpath[baselen + len] = '\0';
@@ -455,7 +455,7 @@ static int remove_path(const char *name)
455
if (ret)
456
return ret;
457
len = strlen(name);
458
- dirs = malloc(len+1);
458
+ dirs = xmalloc(len+1);
459
memcpy(dirs, name, len);
460
dirs[len] = '\0';
461
while ((slash = strrchr(name, '/'))) {
@@ -572,7 +572,7 @@ void update_file_flags(const unsigned char *sha,
572
flush_buffer(fd, buf, size);
573
close(fd);
574
} else if (S_ISLNK(mode)) {
575
- char *lnk = malloc(size + 1);
575
+ char *lnk = xmalloc(size + 1);
576
memcpy(lnk, buf, size);
577
lnk[size] = '\0';
578
mkdir_p(path, 0777);
mktag.c
+1
-1
@@ -119,7 +119,7 @@ static int verify_tag(char *buffer, unsigned long size)
119
int main(int argc, char **argv)
120
{
121
unsigned long size = 4096;
122
- char *buffer = malloc(size);
122
+ char *buffer = xmalloc(size);
123
unsigned char result_sha1[20];
124
125
if (argc != 1)
send-pack.c
+2
-2
@@ -53,7 +53,7 @@ static void exec_rev_list(struct ref *refs)
53
if (900 < i)
54
die("git-rev-list environment overflow");
55
if (!is_zero_sha1(ref->new_sha1)) {
56
- char *buf = malloc(100);
56
+ char *buf = xmalloc(100);
57
args[i++] = buf;
58
snprintf(buf, 50, "%s", sha1_to_hex(ref->new_sha1));
59
buf += 50;
@@ -75,7 +75,7 @@ static void exec_rev_list(struct ref *refs)
75
if (is_zero_sha1(ref->new_sha1) &&
76
!is_zero_sha1(ref->old_sha1) &&
77
has_sha1_file(ref->old_sha1)) {
78
- char *buf = malloc(42);
78
+ char *buf = xmalloc(42);
79
args[i++] = buf;
80
snprintf(buf, 42, "^%s", sha1_to_hex(ref->old_sha1));
81
}
sha1_file.c
+1
-1
@@ -1756,7 +1756,7 @@ int read_pipe(int fd, char** return_buf, unsigned long* return_size)
1756
int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object)
1757
{
1758
unsigned long size = 4096;
1759
- char *buf = malloc(size);
1759
+ char *buf = xmalloc(size);
1760
int ret;
1761
unsigned char hdr[50];
1762
int hdrlen;