summaryrefslogtreecommitdiff
path: root/progress.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2019-04-25 07:41:23 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-04-25 07:41:23 (GMT)
commit449f2db75dd990d5b1157c7d4da49f046eab27c6 (patch)
tree0c33f05bab8cf9a08b6d08f7c8d4bb0cacbc5e5e /progress.c
parentc8e8b5c3251739c4b515e8bf4cdc2fc85297cb14 (diff)
parent999b951b285233d96904b1aad5e0dea22bed55c7 (diff)
downloadgit-449f2db75dd990d5b1157c7d4da49f046eab27c6.zip
git-449f2db75dd990d5b1157c7d4da49f046eab27c6.tar.gz
git-449f2db75dd990d5b1157c7d4da49f046eab27c6.tar.bz2
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.c18
1 files changed, 5 insertions, 13 deletions
diff --git a/progress.c b/progress.c
index 6cde595..0318bdd 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;