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

Commit87a5016

Browse files
author
Neil Conway
committed
Minor code cleanup for pgcrypto: for UDFs declared to be strict, checking
for NULL-ness of function arguments is wasted code.
1 parentd19798e commit87a5016

File tree

2 files changed

+4
-65
lines changed

2 files changed

+4
-65
lines changed

‎contrib/pgcrypto/pgcrypto.c

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727
* SUCH DAMAGE.
2828
*
29-
* $PostgreSQL: pgsql/contrib/pgcrypto/pgcrypto.c,v 1.24 2006/10/04 00:29:46 momjian Exp $
29+
* $PostgreSQL: pgsql/contrib/pgcrypto/pgcrypto.c,v 1.25 2006/11/10 06:28:29 neilc Exp $
3030
*/
3131

3232
#include"postgres.h"
@@ -45,8 +45,7 @@ PG_MODULE_MAGIC;
4545
/* private stuff */
4646

4747
typedefint (*PFN) (constchar*name,void**res);
48-
staticvoid*
49-
find_provider(text*name,PFNpf,char*desc,intsilent);
48+
staticvoid*find_provider(text*name,PFNpf,char*desc,intsilent);
5049

5150
/* SQL function: hash(bytea, text) returns bytea */
5251
PG_FUNCTION_INFO_V1(pg_digest);
@@ -61,9 +60,6 @@ pg_digest(PG_FUNCTION_ARGS)
6160
PX_MD*md;
6261
bytea*res;
6362

64-
if (PG_ARGISNULL(0)||PG_ARGISNULL(1))
65-
PG_RETURN_NULL();
66-
6763
name=PG_GETARG_TEXT_P(1);
6864

6965
/* will give error if fails */
@@ -102,9 +98,6 @@ pg_hmac(PG_FUNCTION_ARGS)
10298
PX_HMAC*h;
10399
bytea*res;
104100

105-
if (PG_ARGISNULL(0)||PG_ARGISNULL(1)||PG_ARGISNULL(2))
106-
PG_RETURN_NULL();
107-
108101
name=PG_GETARG_TEXT_P(2);
109102

110103
/* will give error if fails */
@@ -144,9 +137,6 @@ pg_gen_salt(PG_FUNCTION_ARGS)
144137
text*res;
145138
charbuf[PX_MAX_SALT_LEN+1];
146139

147-
if (PG_ARGISNULL(0))
148-
PG_RETURN_NULL();
149-
150140
arg0=PG_GETARG_TEXT_P(0);
151141

152142
len=VARSIZE(arg0)-VARHDRSZ;
@@ -180,9 +170,6 @@ pg_gen_salt_rounds(PG_FUNCTION_ARGS)
180170
text*res;
181171
charbuf[PX_MAX_SALT_LEN+1];
182172

183-
if (PG_ARGISNULL(0)||PG_ARGISNULL(1))
184-
PG_RETURN_NULL();
185-
186173
arg0=PG_GETARG_TEXT_P(0);
187174
rounds=PG_GETARG_INT32(1);
188175

@@ -222,9 +209,6 @@ pg_crypt(PG_FUNCTION_ARGS)
222209
*resbuf;
223210
text*res;
224211

225-
if (PG_ARGISNULL(0)||PG_ARGISNULL(1))
226-
PG_RETURN_NULL();
227-
228212
arg0=PG_GETARG_TEXT_P(0);
229213
arg1=PG_GETARG_TEXT_P(1);
230214
len0=VARSIZE(arg0)-VARHDRSZ;
@@ -239,9 +223,7 @@ pg_crypt(PG_FUNCTION_ARGS)
239223
buf0[len0]='\0';
240224
buf1[len1]='\0';
241225

242-
resbuf=palloc(PX_MAX_CRYPT);
243-
244-
memset(resbuf,0,PX_MAX_CRYPT);
226+
resbuf=palloc0(PX_MAX_CRYPT);
245227

246228
cres=px_crypt(buf0,buf1,resbuf,PX_MAX_CRYPT);
247229

@@ -282,9 +264,6 @@ pg_encrypt(PG_FUNCTION_ARGS)
282264
klen,
283265
rlen;
284266

285-
if (PG_ARGISNULL(0)||PG_ARGISNULL(1)||PG_ARGISNULL(2))
286-
PG_RETURN_NULL();
287-
288267
type=PG_GETARG_TEXT_P(2);
289268
c=find_provider(type, (PFN)px_find_combo,"Cipher",0);
290269

@@ -334,9 +313,6 @@ pg_decrypt(PG_FUNCTION_ARGS)
334313
klen,
335314
rlen;
336315

337-
if (PG_ARGISNULL(0)||PG_ARGISNULL(1)||PG_ARGISNULL(2))
338-
PG_RETURN_NULL();
339-
340316
type=PG_GETARG_TEXT_P(2);
341317
c=find_provider(type, (PFN)px_find_combo,"Cipher",0);
342318

@@ -387,10 +363,6 @@ pg_encrypt_iv(PG_FUNCTION_ARGS)
387363
ivlen,
388364
rlen;
389365

390-
if (PG_ARGISNULL(0)||PG_ARGISNULL(1)
391-
||PG_ARGISNULL(2)||PG_ARGISNULL(3))
392-
PG_RETURN_NULL();
393-
394366
type=PG_GETARG_TEXT_P(3);
395367
c=find_provider(type, (PFN)px_find_combo,"Cipher",0);
396368

@@ -445,10 +417,6 @@ pg_decrypt_iv(PG_FUNCTION_ARGS)
445417
rlen,
446418
ivlen;
447419

448-
if (PG_ARGISNULL(0)||PG_ARGISNULL(1)
449-
||PG_ARGISNULL(2)||PG_ARGISNULL(3))
450-
PG_RETURN_NULL();
451-
452420
type=PG_GETARG_TEXT_P(3);
453421
c=find_provider(type, (PFN)px_find_combo,"Cipher",0);
454422

‎contrib/pgcrypto/pgp-pgsql.c

Lines changed: 1 addition & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2727
* SUCH DAMAGE.
2828
*
29-
* $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pgsql.c,v 1.7 2005/11/22 18:17:04 momjian Exp $
29+
* $PostgreSQL: pgsql/contrib/pgcrypto/pgp-pgsql.c,v 1.8 2006/11/10 06:28:29 neilc Exp $
3030
*/
3131

3232
#include"postgres.h"
@@ -74,18 +74,6 @@ PG_FUNCTION_INFO_V1(pgp_key_id_w);
7474
PG_FUNCTION_INFO_V1(pg_armor);
7575
PG_FUNCTION_INFO_V1(pg_dearmor);
7676

77-
/*
78-
* check for NULL arguments
79-
*/
80-
#defineCHECK_ARGS() \
81-
do { \
82-
int a; \
83-
for (a = 0; a < PG_NARGS(); a++) { \
84-
if (PG_ARGISNULL(a)) \
85-
PG_RETURN_NULL(); \
86-
} \
87-
} while (0)
88-
8977
/*
9078
* Mix a block of data into RNG.
9179
*/
@@ -660,7 +648,6 @@ pgp_sym_encrypt_bytea(PG_FUNCTION_ARGS)
660648
text*arg=NULL;
661649
text*res;
662650

663-
CHECK_ARGS();
664651
data=PG_GETARG_BYTEA_P(0);
665652
key=PG_GETARG_BYTEA_P(1);
666653
if (PG_NARGS()>2)
@@ -683,7 +670,6 @@ pgp_sym_encrypt_text(PG_FUNCTION_ARGS)
683670
text*arg=NULL;
684671
text*res;
685672

686-
CHECK_ARGS();
687673
data=PG_GETARG_BYTEA_P(0);
688674
key=PG_GETARG_BYTEA_P(1);
689675
if (PG_NARGS()>2)
@@ -707,7 +693,6 @@ pgp_sym_decrypt_bytea(PG_FUNCTION_ARGS)
707693
text*arg=NULL;
708694
text*res;
709695

710-
CHECK_ARGS();
711696
data=PG_GETARG_BYTEA_P(0);
712697
key=PG_GETARG_BYTEA_P(1);
713698
if (PG_NARGS()>2)
@@ -730,7 +715,6 @@ pgp_sym_decrypt_text(PG_FUNCTION_ARGS)
730715
text*arg=NULL;
731716
text*res;
732717

733-
CHECK_ARGS();
734718
data=PG_GETARG_BYTEA_P(0);
735719
key=PG_GETARG_BYTEA_P(1);
736720
if (PG_NARGS()>2)
@@ -757,7 +741,6 @@ pgp_pub_encrypt_bytea(PG_FUNCTION_ARGS)
757741
text*arg=NULL;
758742
text*res;
759743

760-
CHECK_ARGS();
761744
data=PG_GETARG_BYTEA_P(0);
762745
key=PG_GETARG_BYTEA_P(1);
763746
if (PG_NARGS()>2)
@@ -780,7 +763,6 @@ pgp_pub_encrypt_text(PG_FUNCTION_ARGS)
780763
text*arg=NULL;
781764
text*res;
782765

783-
CHECK_ARGS();
784766
data=PG_GETARG_BYTEA_P(0);
785767
key=PG_GETARG_BYTEA_P(1);
786768
if (PG_NARGS()>2)
@@ -805,7 +787,6 @@ pgp_pub_decrypt_bytea(PG_FUNCTION_ARGS)
805787
*arg=NULL;
806788
text*res;
807789

808-
CHECK_ARGS();
809790
data=PG_GETARG_BYTEA_P(0);
810791
key=PG_GETARG_BYTEA_P(1);
811792
if (PG_NARGS()>2)
@@ -833,7 +814,6 @@ pgp_pub_decrypt_text(PG_FUNCTION_ARGS)
833814
*arg=NULL;
834815
text*res;
835816

836-
CHECK_ARGS();
837817
data=PG_GETARG_BYTEA_P(0);
838818
key=PG_GETARG_BYTEA_P(1);
839819
if (PG_NARGS()>2)
@@ -866,9 +846,6 @@ pg_armor(PG_FUNCTION_ARGS)
866846
res_len,
867847
guess_len;
868848

869-
if (PG_ARGISNULL(0))
870-
PG_RETURN_NULL();
871-
872849
data=PG_GETARG_BYTEA_P(0);
873850
data_len=VARSIZE(data)-VARHDRSZ;
874851

@@ -896,9 +873,6 @@ pg_dearmor(PG_FUNCTION_ARGS)
896873
res_len,
897874
guess_len;
898875

899-
if (PG_ARGISNULL(0))
900-
PG_RETURN_NULL();
901-
902876
data=PG_GETARG_TEXT_P(0);
903877
data_len=VARSIZE(data)-VARHDRSZ;
904878

@@ -933,9 +907,6 @@ pgp_key_id_w(PG_FUNCTION_ARGS)
933907
intres_len;
934908
MBuf*buf;
935909

936-
if (PG_ARGISNULL(0))
937-
PG_RETURN_NULL();
938-
939910
data=PG_GETARG_BYTEA_P(0);
940911
buf=create_mbuf_from_vardata(data);
941912
res=palloc(VARHDRSZ+17);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp