commit ec9fc5d3204d86f6d72e04922f16d12190dc77fa
parent 3c2eb96243e4411e41c6dc94c3054f79bc20af14
Author: Benno Schulenberg <bensberg@telfort.nl>
Date: Sun, 13 Oct 2019 17:41:24 +0200
utils: die when trying to allocate zero bytes
This shouldn't occur, so go down when it does.
Diffstat:
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git 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;