{"thread":{"id":"5444","subject":"[PATCH] Use xmalloc instead of malloc","startedAt":"2006-08-31T22:32:39Z","lastAt":"2006-08-31T22:32:39Z","messageCount":1,"participants":["Jonas Fonseca"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"26165","messageId":"20060831223239.GB482@diku.dk","threadId":"5444","inReplyTo":null,"subject":"[PATCH] Use xmalloc instead of malloc","fromName":"Jonas Fonseca","fromEmail":"fonseca@diku.dk","sentAt":"2006-08-31T22:32:39Z","receivedAt":"2006-08-31T22:32:39Z","isPatch":true,"sender":{"key":"fonseca@diku.dk","avatar":"https://gravatar.com/avatar/f82f3ad698717c51873b020c750a92438c820a24056dc39fe4d07baa10a92264?d=mp&s=160"},"body":"Signed-off-by: Jonas Fonseca <fonseca@diku.dk>\n---\n builtin-fmt-merge-msg.c |    6 +++---\n builtin-repo-config.c   |    4 ++--\n config.c                |    4 ++--\n git.c                   |    2 +-\n help.c                  |    2 +-\n merge-recursive.c       |    6 +++---\n mktag.c                 |    2 +-\n send-pack.c             |    4 ++--\n sha1_file.c             |    2 +-\n 9 files changed, 16 insertions(+), 16 deletions(-)\n\ndiff --git a/builtin-fmt-merge-msg.c b/builtin-fmt-merge-msg.c\nindex 76d22b4..ed59e77 100644\n--- a/builtin-fmt-merge-msg.c\n+++ b/builtin-fmt-merge-msg.c\n@@ -140,14 +140,14 @@ static int handle_line(char *line)\n \tif (!strcmp(\".\", src) || !strcmp(src, origin)) {\n \t\tint len = strlen(origin);\n \t\tif (origin[0] == '\\'' && origin[len - 1] == '\\'') {\n-\t\t\tchar *new_origin = malloc(len - 1);\n+\t\t\tchar *new_origin = xmalloc(len - 1);\n \t\t\tmemcpy(new_origin, origin + 1, len - 2);\n \t\t\tnew_origin[len - 1] = 0;\n \t\t\torigin = new_origin;\n \t\t} else\n \t\t\torigin = strdup(origin);\n \t} else {\n-\t\tchar *new_origin = malloc(strlen(origin) + strlen(src) + 5);\n+\t\tchar *new_origin = xmalloc(strlen(origin) + strlen(src) + 5);\n \t\tsprintf(new_origin, \"%s of %s\", origin, src);\n \t\torigin = new_origin;\n \t}\n@@ -214,7 +214,7 @@ static void shortlog(const char *name, u\n \n \t\tif (eol) {\n \t\t\tint len = eol - bol;\n-\t\t\toneline = malloc(len + 1);\n+\t\t\toneline = xmalloc(len + 1);\n \t\t\tmemcpy(oneline, bol, len);\n \t\t\toneline[len] = 0;\n \t\t} else\ndiff --git a/builtin-repo-config.c b/builtin-repo-config.c\nindex 888466c..d19f7dc 100644\n--- a/builtin-repo-config.c\n+++ b/builtin-repo-config.c\n@@ -84,7 +84,7 @@ static int get_value(const char* key_, c\n \t\t*tl = tolower(*tl);\n \n \tif (use_key_regexp) {\n-\t\tkey_regexp = (regex_t*)malloc(sizeof(regex_t));\n+\t\tkey_regexp = (regex_t*)xmalloc(sizeof(regex_t));\n \t\tif (regcomp(key_regexp, key, REG_EXTENDED)) {\n \t\t\tfprintf(stderr, \"Invalid key pattern: %s\\n\", key_);\n \t\t\tgoto free_strings;\n@@ -97,7 +97,7 @@ static int get_value(const char* key_, c\n \t\t\tregex_++;\n \t\t}\n \n-\t\tregexp = (regex_t*)malloc(sizeof(regex_t));\n+\t\tregexp = (regex_t*)xmalloc(sizeof(regex_t));\n \t\tif (regcomp(regexp, regex_, REG_EXTENDED)) {\n \t\t\tfprintf(stderr, \"Invalid pattern: %s\\n\", regex_);\n \t\t\tgoto free_strings;\ndiff --git a/config.c b/config.c\nindex d9f2b78..782cc31 100644\n--- a/config.c\n+++ b/config.c\n@@ -565,7 +565,7 @@ int git_config_set_multivar(const char* \n \t/*\n \t * Validate the key and while at it, lower case it for matching.\n \t */\n-\tstore.key = (char*)malloc(strlen(key)+1);\n+\tstore.key = xmalloc(strlen(key) + 1);\n \tdot = 0;\n \tfor (i = 0; key[i]; i++) {\n \t\tunsigned char c = key[i];\n@@ -633,7 +633,7 @@ int git_config_set_multivar(const char* \n \t\t\t} else\n \t\t\t\tstore.do_not_match = 0;\n \n-\t\t\tstore.value_regex = (regex_t*)malloc(sizeof(regex_t));\n+\t\t\tstore.value_regex = (regex_t*)xmalloc(sizeof(regex_t));\n \t\t\tif (regcomp(store.value_regex, value_regex,\n \t\t\t\t\tREG_EXTENDED)) {\n \t\t\t\tfprintf(stderr, \"Invalid pattern: %s\\n\",\ndiff --git a/git.c b/git.c\nindex bd07289..05871ad 100644\n--- a/git.c\n+++ b/git.c\n@@ -29,7 +29,7 @@ static void prepend_to_path(const char *\n \n \tpath_len = len + strlen(old_path) + 1;\n \n-\tpath = malloc(path_len + 1);\n+\tpath = xmalloc(path_len + 1);\n \n \tmemcpy(path, dir, len);\n \tpath[len] = ':';\ndiff --git a/help.c b/help.c\nindex 9ecdefd..0824c25 100644\n--- a/help.c\n+++ b/help.c\n@@ -184,7 +184,7 @@ static void show_man_page(const char *gi\n \t\tpage = git_cmd;\n \telse {\n \t\tint page_len = strlen(git_cmd) + 4;\n-\t\tchar *p = malloc(page_len + 1);\n+\t\tchar *p = xmalloc(page_len + 1);\n \t\tstrcpy(p, \"git-\");\n \t\tstrcpy(p + 4, git_cmd);\n \t\tp[page_len] = 0;\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex 39a1eae..48b2763 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -283,7 +283,7 @@ static int save_files_dirs(const unsigne\n \t\tunsigned int mode, int stage)\n {\n \tint len = strlen(path);\n-\tchar *newpath = malloc(baselen + len + 1);\n+\tchar *newpath = xmalloc(baselen + len + 1);\n \tmemcpy(newpath, base, baselen);\n \tmemcpy(newpath + baselen, path, len);\n \tnewpath[baselen + len] = '\\0';\n@@ -455,7 +455,7 @@ static int remove_path(const char *name)\n \tif (ret)\n \t\treturn ret;\n \tlen = strlen(name);\n-\tdirs = malloc(len+1);\n+\tdirs = xmalloc(len+1);\n \tmemcpy(dirs, name, len);\n \tdirs[len] = '\\0';\n \twhile ((slash = strrchr(name, '/'))) {\n@@ -572,7 +572,7 @@ void update_file_flags(const unsigned ch\n \t\t\tflush_buffer(fd, buf, size);\n \t\t\tclose(fd);\n \t\t} else if (S_ISLNK(mode)) {\n-\t\t\tchar *lnk = malloc(size + 1);\n+\t\t\tchar *lnk = xmalloc(size + 1);\n \t\t\tmemcpy(lnk, buf, size);\n \t\t\tlnk[size] = '\\0';\n \t\t\tmkdir_p(path, 0777);\ndiff --git a/mktag.c b/mktag.c\nindex be23e58..3448a5d 100644\n--- a/mktag.c\n+++ b/mktag.c\n@@ -119,7 +119,7 @@ #undef PD_FMT\n int main(int argc, char **argv)\n {\n \tunsigned long size = 4096;\n-\tchar *buffer = malloc(size);\n+\tchar *buffer = xmalloc(size);\n \tunsigned char result_sha1[20];\n \n \tif (argc != 1)\ndiff --git a/send-pack.c b/send-pack.c\nindex fd79a61..ac4501d 100644\n--- a/send-pack.c\n+++ b/send-pack.c\n@@ -53,7 +53,7 @@ static void exec_rev_list(struct ref *re\n \t\tif (900 < i)\n \t\t\tdie(\"git-rev-list environment overflow\");\n \t\tif (!is_zero_sha1(ref->new_sha1)) {\n-\t\t\tchar *buf = malloc(100);\n+\t\t\tchar *buf = xmalloc(100);\n \t\t\targs[i++] = buf;\n \t\t\tsnprintf(buf, 50, \"%s\", sha1_to_hex(ref->new_sha1));\n \t\t\tbuf += 50;\n@@ -75,7 +75,7 @@ static void exec_rev_list(struct ref *re\n \t\tif (is_zero_sha1(ref->new_sha1) &&\n \t\t    !is_zero_sha1(ref->old_sha1) &&\n \t\t    has_sha1_file(ref->old_sha1)) {\n-\t\t\tchar *buf = malloc(42);\n+\t\t\tchar *buf = xmalloc(42);\n \t\t\targs[i++] = buf;\n \t\t\tsnprintf(buf, 42, \"^%s\", sha1_to_hex(ref->old_sha1));\n \t\t}\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 01aa745..912e1cc 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -1774,7 +1774,7 @@ int read_pipe(int fd, char** return_buf,\n int index_pipe(unsigned char *sha1, int fd, const char *type, int write_object)\n {\n \tunsigned long size = 4096;\n-\tchar *buf = malloc(size);\n+\tchar *buf = xmalloc(size);\n \tint ret;\n \tunsigned char hdr[50];\n \tint hdrlen;\n-- \n1.4.2.g2ba6b-dirty\n\n-- \nJonas Fonseca\n"}]}