summaryrefslogtreecommitdiff
path: root/src/port/dirmod.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/port/dirmod.c')
-rw-r--r--src/port/dirmod.c12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/port/dirmod.c b/src/port/dirmod.c
index 22f5c591b07..514424f82e6 100644
--- a/src/port/dirmod.c
+++ b/src/port/dirmod.c
@@ -70,7 +70,11 @@ fe_palloc(Size size)
{
void *res;
- if ((res = malloc(size)) == NULL)
+ /* Avoid unportable behavior of malloc(0) */
+ if (size == 0)
+ size = 1;
+ res = malloc(size);
+ if (res == NULL)
{
fprintf(stderr, _("out of memory\n"));
exit(1);
@@ -96,7 +100,11 @@ fe_repalloc(void *pointer, Size size)
{
void *res;
- if ((res = realloc(pointer, size)) == NULL)
+ /* Avoid unportable behavior of realloc(NULL, 0) */
+ if (pointer == NULL && size == 0)
+ size = 1;
+ res = realloc(pointer, size);
+ if (res == NULL)
{
fprintf(stderr, _("out of memory\n"));
exit(1);