summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNeil Conway2006-11-10 06:28:29 +0000
committerNeil Conway2006-11-10 06:28:29 +0000
commit04c915db8454bc7da3c79e3c4973abc68216a06f (patch)
tree7f25df320289c6ba3509c35dad4df7d8c1bc223f
parent814ab9c3fa4220fedbf2b92667bbb02a54012e38 (diff)
Minor code cleanup for pgcrypto: for UDFs declared to be strict, checking
for NULL-ness of function arguments is wasted code.
-rw-r--r--contrib/pgcrypto/pgcrypto.c36
-rw-r--r--contrib/pgcrypto/pgp-pgsql.c29
2 files changed, 2 insertions, 63 deletions
diff --git a/contrib/pgcrypto/pgcrypto.c b/contrib/pgcrypto/pgcrypto.c
index 36e5f0373c..96dc3af81a 100644
--- a/contrib/pgcrypto/pgcrypto.c
+++ b/contrib/pgcrypto/pgcrypto.c
@@ -45,8 +45,7 @@ PG_MODULE_MAGIC;
/* private stuff */
typedef int (*PFN) (const char *name, void **res);
-static void *
- find_provider(text *name, PFN pf, char *desc, int silent);
+static void *find_provider(text *name, PFN pf, char *desc, int silent);
/* SQL function: hash(bytea, text) returns bytea */
PG_FUNCTION_INFO_V1(pg_digest);
@@ -61,9 +60,6 @@ pg_digest(PG_FUNCTION_ARGS)
PX_MD *md;
bytea *res;
- if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
- PG_RETURN_NULL();
-
name = PG_GETARG_TEXT_P(1);
/* will give error if fails */
@@ -102,9 +98,6 @@ pg_hmac(PG_FUNCTION_ARGS)
PX_HMAC *h;
bytea *res;
- if (PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2))
- PG_RETURN_NULL();
-
name = PG_GETARG_TEXT_P(2);
/* will give error if fails */
@@ -144,9 +137,6 @@ pg_gen_salt(PG_FUNCTION_ARGS)
text *res;
char buf[PX_MAX_SALT_LEN + 1];
- if (PG_ARGISNULL(0))
- PG_RETURN_NULL();
-
arg0 = PG_GETARG_TEXT_P(0);
len = VARSIZE(arg0) - VARHDRSZ;
@@ -180,9 +170,6 @@ pg_gen_salt_rounds(PG_FUNCTION_ARGS)
text *res;
char buf[PX_MAX_SALT_LEN + 1];
- if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
- PG_RETURN_NULL();
-
arg0 = PG_GETARG_TEXT_P(0);
rounds = PG_GETARG_INT32(1);
@@ -222,9 +209,6 @@ pg_crypt(PG_FUNCTION_ARGS)
*resbuf;
text *res;
- if (PG_ARGISNULL(0) || PG_ARGISNULL(1))
- PG_RETURN_NULL();
-
arg0 = PG_GETARG_TEXT_P(0);
arg1 = PG_GETARG_TEXT_P(1);
len0 = VARSIZE(arg0) - VARHDRSZ;
@@ -239,9 +223,7 @@ pg_crypt(PG_FUNCTION_ARGS)
buf0[len0] = '\0';
buf1[len1] = '\0';
- resbuf = palloc(PX_MAX_CRYPT);
-
- memset(resbuf, 0, PX_MAX_CRYPT);
+ resbuf = palloc0(PX_MAX_CRYPT);
cres = px_crypt(buf0, buf1, resbuf, PX_MAX_CRYPT);
@@ -282,9 +264,6 @@ pg_encrypt(PG_FUNCTION_ARGS)
klen,
rlen;
- if (PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2))
- PG_RETURN_NULL();
-
type = PG_GETARG_TEXT_P(2);
c = find_provider(type, (PFN) px_find_combo, "Cipher", 0);
@@ -334,9 +313,6 @@ pg_decrypt(PG_FUNCTION_ARGS)
klen,
rlen;
- if (PG_ARGISNULL(0) || PG_ARGISNULL(1) || PG_ARGISNULL(2))
- PG_RETURN_NULL();
-
type = PG_GETARG_TEXT_P(2);
c = find_provider(type, (PFN) px_find_combo, "Cipher", 0);
@@ -387,10 +363,6 @@ pg_encrypt_iv(PG_FUNCTION_ARGS)
ivlen,
rlen;
- if (PG_ARGISNULL(0) || PG_ARGISNULL(1)
- || PG_ARGISNULL(2) || PG_ARGISNULL(3))
- PG_RETURN_NULL();
-
type = PG_GETARG_TEXT_P(3);
c = find_provider(type, (PFN) px_find_combo, "Cipher", 0);
@@ -445,10 +417,6 @@ pg_decrypt_iv(PG_FUNCTION_ARGS)
rlen,
ivlen;
- if (PG_ARGISNULL(0) || PG_ARGISNULL(1)
- || PG_ARGISNULL(2) || PG_ARGISNULL(3))
- PG_RETURN_NULL();
-
type = PG_GETARG_TEXT_P(3);
c = find_provider(type, (PFN) px_find_combo, "Cipher", 0);
diff --git a/contrib/pgcrypto/pgp-pgsql.c b/contrib/pgcrypto/pgp-pgsql.c
index 1ca81d9b89..8a0b0727ab 100644
--- a/contrib/pgcrypto/pgp-pgsql.c
+++ b/contrib/pgcrypto/pgp-pgsql.c
@@ -75,18 +75,6 @@ PG_FUNCTION_INFO_V1(pg_armor);
PG_FUNCTION_INFO_V1(pg_dearmor);
/*
- * check for NULL arguments
- */
-#define CHECK_ARGS() \
- do { \
- int a; \
- for (a = 0; a < PG_NARGS(); a++) { \
- if (PG_ARGISNULL(a)) \
- PG_RETURN_NULL(); \
- } \
- } while (0)
-
-/*
* Mix a block of data into RNG.
*/
static void
@@ -660,7 +648,6 @@ pgp_sym_encrypt_bytea(PG_FUNCTION_ARGS)
text *arg = NULL;
text *res;
- CHECK_ARGS();
data = PG_GETARG_BYTEA_P(0);
key = PG_GETARG_BYTEA_P(1);
if (PG_NARGS() > 2)
@@ -683,7 +670,6 @@ pgp_sym_encrypt_text(PG_FUNCTION_ARGS)
text *arg = NULL;
text *res;
- CHECK_ARGS();
data = PG_GETARG_BYTEA_P(0);
key = PG_GETARG_BYTEA_P(1);
if (PG_NARGS() > 2)
@@ -707,7 +693,6 @@ pgp_sym_decrypt_bytea(PG_FUNCTION_ARGS)
text *arg = NULL;
text *res;
- CHECK_ARGS();
data = PG_GETARG_BYTEA_P(0);
key = PG_GETARG_BYTEA_P(1);
if (PG_NARGS() > 2)
@@ -730,7 +715,6 @@ pgp_sym_decrypt_text(PG_FUNCTION_ARGS)
text *arg = NULL;
text *res;
- CHECK_ARGS();
data = PG_GETARG_BYTEA_P(0);
key = PG_GETARG_BYTEA_P(1);
if (PG_NARGS() > 2)
@@ -757,7 +741,6 @@ pgp_pub_encrypt_bytea(PG_FUNCTION_ARGS)
text *arg = NULL;
text *res;
- CHECK_ARGS();
data = PG_GETARG_BYTEA_P(0);
key = PG_GETARG_BYTEA_P(1);
if (PG_NARGS() > 2)
@@ -780,7 +763,6 @@ pgp_pub_encrypt_text(PG_FUNCTION_ARGS)
text *arg = NULL;
text *res;
- CHECK_ARGS();
data = PG_GETARG_BYTEA_P(0);
key = PG_GETARG_BYTEA_P(1);
if (PG_NARGS() > 2)
@@ -805,7 +787,6 @@ pgp_pub_decrypt_bytea(PG_FUNCTION_ARGS)
*arg = NULL;
text *res;
- CHECK_ARGS();
data = PG_GETARG_BYTEA_P(0);
key = PG_GETARG_BYTEA_P(1);
if (PG_NARGS() > 2)
@@ -833,7 +814,6 @@ pgp_pub_decrypt_text(PG_FUNCTION_ARGS)
*arg = NULL;
text *res;
- CHECK_ARGS();
data = PG_GETARG_BYTEA_P(0);
key = PG_GETARG_BYTEA_P(1);
if (PG_NARGS() > 2)
@@ -866,9 +846,6 @@ pg_armor(PG_FUNCTION_ARGS)
res_len,
guess_len;
- if (PG_ARGISNULL(0))
- PG_RETURN_NULL();
-
data = PG_GETARG_BYTEA_P(0);
data_len = VARSIZE(data) - VARHDRSZ;
@@ -896,9 +873,6 @@ pg_dearmor(PG_FUNCTION_ARGS)
res_len,
guess_len;
- if (PG_ARGISNULL(0))
- PG_RETURN_NULL();
-
data = PG_GETARG_TEXT_P(0);
data_len = VARSIZE(data) - VARHDRSZ;
@@ -933,9 +907,6 @@ pgp_key_id_w(PG_FUNCTION_ARGS)
int res_len;
MBuf *buf;
- if (PG_ARGISNULL(0))
- PG_RETURN_NULL();
-
data = PG_GETARG_BYTEA_P(0);
buf = create_mbuf_from_vardata(data);
res = palloc(VARHDRSZ + 17);