diff options
author | Junio C Hamano <gitster@pobox.com> | 2019-04-25 09:41:23 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2019-04-25 09:41:23 +0200 |
commit | 449f2db75dd990d5b1157c7d4da49f046eab27c6 (patch) | |
tree | 0c33f05bab8cf9a08b6d08f7c8d4bb0cacbc5e5e /progress.c | |
parent | Merge branch 'km/t3000-retitle' (diff) | |
parent | progress: use xmalloc/xcalloc (diff) | |
download | git-449f2db75dd990d5b1157c7d4da49f046eab27c6.tar.xz git-449f2db75dd990d5b1157c7d4da49f046eab27c6.zip |
Merge branch 'jk/xmalloc'
The code is updated to check the result of memory allocation before
it is used in more places, by using xmalloc and/or xcalloc calls.
* jk/xmalloc:
progress: use xmalloc/xcalloc
xdiff: use xmalloc/xrealloc
xdiff: use git-compat-util
test-prio-queue: use xmalloc
Diffstat (limited to 'progress.c')
-rw-r--r-- | progress.c | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/progress.c b/progress.c index 6cde5959fa..0318bdd41b 100644 --- a/progress.c +++ b/progress.c @@ -167,12 +167,10 @@ void display_throughput(struct progress *progress, uint64_t total) now_ns = getnanotime(); if (!tp) { - progress->throughput = tp = calloc(1, sizeof(*tp)); - if (tp) { - tp->prev_total = tp->curr_total = total; - tp->prev_ns = now_ns; - strbuf_init(&tp->display, 0); - } + progress->throughput = tp = xcalloc(1, sizeof(*tp)); + tp->prev_total = tp->curr_total = total; + tp->prev_ns = now_ns; + strbuf_init(&tp->display, 0); return; } tp->curr_total = total; @@ -225,13 +223,7 @@ void display_progress(struct progress *progress, uint64_t n) static struct progress *start_progress_delay(const char *title, uint64_t total, unsigned delay, unsigned sparse) { - struct progress *progress = malloc(sizeof(*progress)); - if (!progress) { - /* unlikely, but here's a good fallback */ - fprintf(stderr, "%s...\n", title); - fflush(stderr); - return NULL; - } + struct progress *progress = xmalloc(sizeof(*progress)); progress->title = title; progress->total = total; progress->last_value = -1; |