]> granicus.if.org Git - git/commitdiff
test-prio-queue: use xmalloc
authorJeff King <peff@peff.net>
Thu, 11 Apr 2019 13:48:14 +0000 (09:48 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 12 Apr 2019 04:34:17 +0000 (13:34 +0900)
test-prio-queue.c doesn't check the return value of malloc, and could
segfault.

It's unlikely for this to matter in practice; it's a small allocation,
and this code isn't even installed alongside the rest of Git. But let's
use xmalloc(), which makes auditing for other accidental uses of bare
malloc() easier.

Reported-by: 王健强 <jianqiang.wang@securitygossip.com>
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/helper/test-prio-queue.c

index 5bc9c46ea5603e22e6fb5aaa5c0276a12d2a031f..f4028442e37e39d7ec35abf00c237d4d2cbac892 100644 (file)
@@ -40,7 +40,7 @@ int cmd__prio_queue(int argc, const char **argv)
                } else if (!strcmp(*argv, "stack")) {
                        pq.compare = NULL;
                } else {
-                       int *v = malloc(sizeof(*v));
+                       int *v = xmalloc(sizeof(*v));
                        *v = atoi(*argv);
                        prio_queue_put(&pq, v);
                }