diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/backend/utils/misc/guc.c | 6 | ||||
-rw-r--r-- | src/bin/initdb/initdb.c | 3 | ||||
-rw-r--r-- | src/bin/pg_basebackup/streamutil.c | 3 | ||||
-rw-r--r-- | src/bin/pg_ctl/pg_ctl.c | 3 | ||||
-rw-r--r-- | src/bin/pg_dump/dumpmem.c | 6 | ||||
-rw-r--r-- | src/bin/psql/common.c | 3 | ||||
-rw-r--r-- | src/bin/psql/print.c | 3 | ||||
-rw-r--r-- | src/port/dirmod.c | 12 |
8 files changed, 37 insertions, 2 deletions
diff --git a/src/backend/utils/misc/guc.c b/src/backend/utils/misc/guc.c index 7f54d452eae..9ab13475575 100644 --- a/src/backend/utils/misc/guc.c +++ b/src/backend/utils/misc/guc.c @@ -3352,6 +3352,9 @@ guc_malloc(int elevel, size_t size) { void *data; + /* Avoid unportable behavior of malloc(0) */ + if (size == 0) + size = 1; data = malloc(size); if (data == NULL) ereport(elevel, @@ -3365,6 +3368,9 @@ guc_realloc(int elevel, void *old, size_t size) { void *data; + /* Avoid unportable behavior of realloc(NULL, 0) */ + if (old == NULL && size == 0) + size = 1; data = realloc(old, size); if (data == NULL) ereport(elevel, diff --git a/src/bin/initdb/initdb.c b/src/bin/initdb/initdb.c index 74046b5dfea..a2f16a01c3c 100644 --- a/src/bin/initdb/initdb.c +++ b/src/bin/initdb/initdb.c @@ -285,6 +285,9 @@ pg_malloc(size_t size) { void *result; + /* Avoid unportable behavior of malloc(0) */ + if (size == 0) + size = 1; result = malloc(size); if (!result) { diff --git a/src/bin/pg_basebackup/streamutil.c b/src/bin/pg_basebackup/streamutil.c index c32c5acb2b9..e5fd6fd7655 100644 --- a/src/bin/pg_basebackup/streamutil.c +++ b/src/bin/pg_basebackup/streamutil.c @@ -54,6 +54,9 @@ xmalloc0(int size) { void *result; + /* Avoid unportable behavior of malloc(0) */ + if (size == 0) + size = 1; result = malloc(size); if (!result) { diff --git a/src/bin/pg_ctl/pg_ctl.c b/src/bin/pg_ctl/pg_ctl.c index 72fc4c1abf6..b288e9a8a63 100644 --- a/src/bin/pg_ctl/pg_ctl.c +++ b/src/bin/pg_ctl/pg_ctl.c @@ -233,6 +233,9 @@ pg_malloc(size_t size) { void *result; + /* Avoid unportable behavior of malloc(0) */ + if (size == 0) + size = 1; result = malloc(size); if (!result) { diff --git a/src/bin/pg_dump/dumpmem.c b/src/bin/pg_dump/dumpmem.c index 3ef10307bc5..cadc89d4447 100644 --- a/src/bin/pg_dump/dumpmem.c +++ b/src/bin/pg_dump/dumpmem.c @@ -42,6 +42,9 @@ pg_malloc(size_t size) { void *tmp; + /* Avoid unportable behavior of malloc(0) */ + if (size == 0) + size = 1; tmp = malloc(size); if (!tmp) exit_horribly(NULL, "out of memory\n"); @@ -64,6 +67,9 @@ pg_realloc(void *ptr, size_t size) { void *tmp; + /* Avoid unportable behavior of realloc(NULL, 0) */ + if (ptr == NULL && size == 0) + size = 1; tmp = realloc(ptr, size); if (!tmp) exit_horribly(NULL, "out of memory\n"); diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c index 330d5ce12cf..c804148cd57 100644 --- a/src/bin/psql/common.c +++ b/src/bin/psql/common.c @@ -60,6 +60,9 @@ pg_malloc(size_t size) { void *tmp; + /* Avoid unportable behavior of malloc(0) */ + if (size == 0) + size = 1; tmp = malloc(size); if (!tmp) { diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c index 8fa5e371284..6da3ba053e0 100644 --- a/src/bin/psql/print.c +++ b/src/bin/psql/print.c @@ -136,6 +136,9 @@ pg_local_malloc(size_t size) { void *tmp; + /* Avoid unportable behavior of malloc(0) */ + if (size == 0) + size = 1; tmp = malloc(size); if (!tmp) { 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); |