summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Conway2006-03-19 22:22:56 +0000
committerNeil Conway2006-03-19 22:22:56 +0000
commit30887f8e886578642bd39e1a1219cf9d55a4e901 (patch)
tree79f0802aff4c7a71d78cdd68831a5fd7878b0922
parentbafd4175c20067becdc8d4206b6390821f5d0081 (diff)
Fix a few places that were checking for the return value of palloc() to be
non-NULL: palloc() ereports on OOM, so we can safely assume it returns a valid pointer.
-rw-r--r--contrib/chkpass/chkpass.c16
-rw-r--r--contrib/fuzzystrmatch/fuzzystrmatch.c4
-rw-r--r--src/backend/utils/adt/cash.c11
-rw-r--r--src/pl/plperl/SPI.xs6
-rw-r--r--src/pl/plperl/plperl.c4
5 files changed, 8 insertions, 33 deletions
diff --git a/contrib/chkpass/chkpass.c b/contrib/chkpass/chkpass.c
index ddd61081b4..7af6703b77 100644
--- a/contrib/chkpass/chkpass.c
+++ b/contrib/chkpass/chkpass.c
@@ -108,11 +108,9 @@ chkpass_out(PG_FUNCTION_ARGS)
chkpass *password = (chkpass *) PG_GETARG_POINTER(0);
char *result;
- if ((result = (char *) palloc(16)) != NULL)
- {
- result[0] = ':';
- strcpy(result + 1, password->password);
- }
+ result = (char *) palloc(16);
+ result[0] = ':';
+ strcpy(result + 1, password->password);
PG_RETURN_CSTRING(result);
}
@@ -129,11 +127,9 @@ chkpass_rout(PG_FUNCTION_ARGS)
chkpass *password = (chkpass *) PG_GETARG_POINTER(0);
text *result;
- if ((result = (text *) palloc(VARHDRSZ + 16)) != NULL)
- {
- result->vl_len = VARHDRSZ + strlen(password->password);
- memcpy(result->vl_dat, password->password, strlen(password->password));
- }
+ result = (text *) palloc(VARHDRSZ + 16);
+ result->vl_len = VARHDRSZ + strlen(password->password);
+ memcpy(result->vl_dat, password->password, strlen(password->password));
PG_RETURN_TEXT_P(result);
}
diff --git a/contrib/fuzzystrmatch/fuzzystrmatch.c b/contrib/fuzzystrmatch/fuzzystrmatch.c
index 5a9205592e..a0b5d08314 100644
--- a/contrib/fuzzystrmatch/fuzzystrmatch.c
+++ b/contrib/fuzzystrmatch/fuzzystrmatch.c
@@ -347,14 +347,10 @@ _metaphone(
if (max_phonemes == 0)
{ /* Assume largest possible */
*phoned_word = palloc(sizeof(char) * strlen(word) +1);
- if (!*phoned_word)
- return META_ERROR;
}
else
{
*phoned_word = palloc(sizeof(char) * max_phonemes + 1);
- if (!*phoned_word)
- return META_ERROR;
}
/*-- The first phoneme has to be processed specially. --*/
diff --git a/src/backend/utils/adt/cash.c b/src/backend/utils/adt/cash.c
index 254f3864da..eccbd1cf63 100644
--- a/src/backend/utils/adt/cash.c
+++ b/src/backend/utils/adt/cash.c
@@ -291,10 +291,7 @@ cash_out(PG_FUNCTION_ARGS)
/* see if we need to signify negative amount */
if (minus)
{
- if (!PointerIsValid(result = palloc(CASH_BUFSZ + 2 - count + strlen(nsymbol))))
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory")));
+ result = palloc(CASH_BUFSZ + 2 - count + strlen(nsymbol));
/* Position code of 0 means use parens */
if (convention == 0)
@@ -306,11 +303,7 @@ cash_out(PG_FUNCTION_ARGS)
}
else
{
- if (!PointerIsValid(result = palloc(CASH_BUFSZ + 2 - count)))
- ereport(ERROR,
- (errcode(ERRCODE_OUT_OF_MEMORY),
- errmsg("out of memory")));
-
+ result = palloc(CASH_BUFSZ + 2 - count);
strcpy(result, buf + count);
}
diff --git a/src/pl/plperl/SPI.xs b/src/pl/plperl/SPI.xs
index 738cbb6184..967ac0adba 100644
--- a/src/pl/plperl/SPI.xs
+++ b/src/pl/plperl/SPI.xs
@@ -151,8 +151,6 @@ spi_spi_prepare(query, ...)
if (items < 1)
Perl_croak(aTHX_ "Usage: spi_prepare(query, ...)");
argv = ( SV**) palloc(( items - 1) * sizeof(SV*));
- if ( argv == NULL)
- Perl_croak(aTHX_ "spi_prepare: not enough memory");
for ( i = 1; i < items; i++)
argv[i - 1] = ST(i);
RETVAL = plperl_spi_prepare(query, items - 1, argv);
@@ -179,8 +177,6 @@ spi_spi_exec_prepared(query, ...)
}
argc = items - offset;
argv = ( SV**) palloc( argc * sizeof(SV*));
- if ( argv == NULL)
- Perl_croak(aTHX_ "spi_exec_prepared: not enough memory");
for ( i = 0; offset < items; offset++, i++)
argv[i] = ST(offset);
ret_hash = plperl_spi_exec_prepared(query, attr, argc, argv);
@@ -199,8 +195,6 @@ spi_spi_query_prepared(query, ...)
Perl_croak(aTHX_ "Usage: spi_query_prepared(query, "
"[\\@bind_values])");
argv = ( SV**) palloc(( items - 1) * sizeof(SV*));
- if ( argv == NULL)
- Perl_croak(aTHX_ "spi_query_prepared: not enough memory");
for ( i = 1; i < items; i++)
argv[i - 1] = ST(i);
RETVAL = plperl_spi_query_prepared(query, items - 1, argv);
diff --git a/src/pl/plperl/plperl.c b/src/pl/plperl/plperl.c
index a7f05efd84..0d5c16da32 100644
--- a/src/pl/plperl/plperl.c
+++ b/src/pl/plperl/plperl.c
@@ -2122,8 +2122,6 @@ plperl_spi_exec_prepared(char* query, HV * attr, int argc, SV ** argv)
{
nulls = (char *)palloc( argc);
argvalues = (Datum *) palloc(argc * sizeof(Datum));
- if ( nulls == NULL || argvalues == NULL)
- elog(ERROR, "spi_exec_prepared: not enough memory");
}
else
{
@@ -2253,8 +2251,6 @@ plperl_spi_query_prepared(char* query, int argc, SV ** argv)
{
nulls = (char *)palloc( argc);
argvalues = (Datum *) palloc(argc * sizeof(Datum));
- if ( nulls == NULL || argvalues == NULL)
- elog(ERROR, "spi_query_prepared: not enough memory");
}
else
{