Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita323ede

Browse files
author
Neil Conway
committed
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 avalid pointer.
1 parent381cb04 commita323ede

File tree

5 files changed

+12
-37
lines changed

5 files changed

+12
-37
lines changed

‎contrib/chkpass/chkpass.c

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* darcy@druid.net
55
* http://www.druid.net/darcy/
66
*
7-
* $PostgreSQL: pgsql/contrib/chkpass/chkpass.c,v 1.14 2005/10/15 02:49:04 momjian Exp $
7+
* $PostgreSQL: pgsql/contrib/chkpass/chkpass.c,v 1.15 2006/03/19 22:22:55 neilc Exp $
88
* best viewed with tabs set to 4
99
*/
1010

@@ -108,11 +108,9 @@ chkpass_out(PG_FUNCTION_ARGS)
108108
chkpass*password= (chkpass*)PG_GETARG_POINTER(0);
109109
char*result;
110110

111-
if ((result= (char*)palloc(16))!=NULL)
112-
{
113-
result[0]=':';
114-
strcpy(result+1,password->password);
115-
}
111+
result= (char*)palloc(16);
112+
result[0]=':';
113+
strcpy(result+1,password->password);
116114

117115
PG_RETURN_CSTRING(result);
118116
}
@@ -129,11 +127,9 @@ chkpass_rout(PG_FUNCTION_ARGS)
129127
chkpass*password= (chkpass*)PG_GETARG_POINTER(0);
130128
text*result;
131129

132-
if ((result= (text*)palloc(VARHDRSZ+16))!=NULL)
133-
{
134-
result->vl_len=VARHDRSZ+strlen(password->password);
135-
memcpy(result->vl_dat,password->password,strlen(password->password));
136-
}
130+
result= (text*)palloc(VARHDRSZ+16);
131+
result->vl_len=VARHDRSZ+strlen(password->password);
132+
memcpy(result->vl_dat,password->password,strlen(password->password));
137133

138134
PG_RETURN_TEXT_P(result);
139135
}

‎contrib/fuzzystrmatch/fuzzystrmatch.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*
66
* Joe Conway <mail@joeconway.com>
77
*
8-
* $PostgreSQL: pgsql/contrib/fuzzystrmatch/fuzzystrmatch.c,v 1.19 2006/03/11 04:38:29 momjian Exp $
8+
* $PostgreSQL: pgsql/contrib/fuzzystrmatch/fuzzystrmatch.c,v 1.20 2006/03/19 22:22:56 neilc Exp $
99
* Copyright (c) 2001-2006, PostgreSQL Global Development Group
1010
* ALL RIGHTS RESERVED;
1111
*
@@ -347,14 +347,10 @@ _metaphone(
347347
if (max_phonemes==0)
348348
{/* Assume largest possible */
349349
*phoned_word=palloc(sizeof(char)*strlen(word)+1);
350-
if (!*phoned_word)
351-
returnMETA_ERROR;
352350
}
353351
else
354352
{
355353
*phoned_word=palloc(sizeof(char)*max_phonemes+1);
356-
if (!*phoned_word)
357-
returnMETA_ERROR;
358354
}
359355

360356
/*-- The first phoneme has to be processed specially. --*/

‎src/backend/utils/adt/cash.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* workings can be found in the book "Software Solutions in C" by
1010
* Dale Schumacher, Academic Press, ISBN: 0-12-632360-7.
1111
*
12-
* $PostgreSQL: pgsql/src/backend/utils/adt/cash.c,v 1.66 2005/10/15 02:49:28 momjian Exp $
12+
* $PostgreSQL: pgsql/src/backend/utils/adt/cash.c,v 1.67 2006/03/19 22:22:56 neilc Exp $
1313
*/
1414

1515
#include"postgres.h"
@@ -291,10 +291,7 @@ cash_out(PG_FUNCTION_ARGS)
291291
/* see if we need to signify negative amount */
292292
if (minus)
293293
{
294-
if (!PointerIsValid(result=palloc(CASH_BUFSZ+2-count+strlen(nsymbol))))
295-
ereport(ERROR,
296-
(errcode(ERRCODE_OUT_OF_MEMORY),
297-
errmsg("out of memory")));
294+
result=palloc(CASH_BUFSZ+2-count+strlen(nsymbol));
298295

299296
/* Position code of 0 means use parens */
300297
if (convention==0)
@@ -306,11 +303,7 @@ cash_out(PG_FUNCTION_ARGS)
306303
}
307304
else
308305
{
309-
if (!PointerIsValid(result=palloc(CASH_BUFSZ+2-count)))
310-
ereport(ERROR,
311-
(errcode(ERRCODE_OUT_OF_MEMORY),
312-
errmsg("out of memory")));
313-
306+
result=palloc(CASH_BUFSZ+2-count);
314307
strcpy(result,buf+count);
315308
}
316309

‎src/pl/plperl/SPI.xs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ spi_spi_prepare(query, ...)
151151
if (items<1)
152152
Perl_croak(aTHX_"Usage: spi_prepare(query, ...)");
153153
argv= (SV**)palloc((items-1)*sizeof(SV*));
154-
if (argv==NULL)
155-
Perl_croak(aTHX_"spi_prepare: not enough memory");
156154
for (i=1;i<items;i++)
157155
argv[i-1]=ST(i);
158156
RETVAL=plperl_spi_prepare(query,items-1,argv);
@@ -179,8 +177,6 @@ spi_spi_exec_prepared(query, ...)
179177
}
180178
argc=items-offset;
181179
argv= (SV**)palloc(argc*sizeof(SV*));
182-
if (argv==NULL)
183-
Perl_croak(aTHX_"spi_exec_prepared: not enough memory");
184180
for (i=0;offset<items;offset++,i++)
185181
argv[i]=ST(offset);
186182
ret_hash=plperl_spi_exec_prepared(query,attr,argc,argv);
@@ -199,8 +195,6 @@ spi_spi_query_prepared(query, ...)
199195
Perl_croak(aTHX_"Usage: spi_query_prepared(query, "
200196
"[\\@bind_values])");
201197
argv= (SV**)palloc((items-1)*sizeof(SV*));
202-
if (argv==NULL)
203-
Perl_croak(aTHX_"spi_query_prepared: not enough memory");
204198
for (i=1;i<items;i++)
205199
argv[i-1]=ST(i);
206200
RETVAL=plperl_spi_query_prepared(query,items-1,argv);

‎src/pl/plperl/plperl.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/**********************************************************************
22
* plperl.c - perl as a procedural language for PostgreSQL
33
*
4-
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.106 2006/03/14 22:48:23 tgl Exp $
4+
* $PostgreSQL: pgsql/src/pl/plperl/plperl.c,v 1.107 2006/03/19 22:22:56 neilc Exp $
55
*
66
**********************************************************************/
77

@@ -2122,8 +2122,6 @@ plperl_spi_exec_prepared(char* query, HV * attr, int argc, SV ** argv)
21222122
{
21232123
nulls= (char*)palloc(argc);
21242124
argvalues= (Datum*)palloc(argc*sizeof(Datum));
2125-
if (nulls==NULL||argvalues==NULL)
2126-
elog(ERROR,"spi_exec_prepared: not enough memory");
21272125
}
21282126
else
21292127
{
@@ -2253,8 +2251,6 @@ plperl_spi_query_prepared(char* query, int argc, SV ** argv)
22532251
{
22542252
nulls= (char*)palloc(argc);
22552253
argvalues= (Datum*)palloc(argc*sizeof(Datum));
2256-
if (nulls==NULL||argvalues==NULL)
2257-
elog(ERROR,"spi_query_prepared: not enough memory");
22582254
}
22592255
else
22602256
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp