From ec9fc5d3204d86f6d72e04922f16d12190dc77fa Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Sun, 13 Oct 2019 17:41:24 +0200 Subject: [PATCH] utils: die when trying to allocate zero bytes This shouldn't occur, so go down when it does. --- src/utils.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/utils.c b/src/utils.c index 8bcc688c..75f2cc61 100644 --- a/src/utils.c +++ b/src/utils.c @@ -294,7 +294,10 @@ void *nmalloc(size_t howmuch) { void *r = malloc(howmuch); - if (r == NULL && howmuch != 0) + if (howmuch == 0) + die("Allocating zero bytes. Please report a bug.\n"); + + if (r == NULL) die(_("Nano is out of memory!\n")); return r; @@ -306,7 +309,10 @@ void *nrealloc(void *ptr, size_t howmuch) { void *r = realloc(ptr, howmuch); - if (r == NULL && howmuch != 0) + if (howmuch == 0) + die("Allocating zero bytes. Please report a bug.\n"); + + if (r == NULL) die(_("Nano is out of memory!\n")); return r;