From 7af522ecdb4501fdd5ccd6b3c1b0f283d53cce93 Mon Sep 17 00:00:00 2001 From: dmitrystas Date: Sat, 17 Jun 2023 21:01:29 +0200 Subject: [PATCH] Fix null The function should return null in case the data is null, for consistency with existing hashing functions like md5, digest, etc --- pg_blake2b.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pg_blake2b.c b/pg_blake2b.c index d123fbc..86a4b4d 100644 --- a/pg_blake2b.c +++ b/pg_blake2b.c @@ -13,13 +13,21 @@ pg_blake2b(PG_FUNCTION_ARGS) bytea *digest; bytea *key = NULL; - bytea *data = PG_GETARG_BYTEA_PP(0); + bytea *data; size_t keylen = 0; - size_t datalen = VARSIZE(data) - VARHDRSZ; + size_t datalen; int16 digest_size = BLAKE2B_OUTBYTES; + if (PG_ARGISNULL(0)) + { + PG_RETURN_NULL(); + } + + data = PG_GETARG_BYTEA_PP(0); + datalen = VARSIZE(data) - VARHDRSZ; + if (!PG_ARGISNULL(1)) { digest_size = PG_GETARG_INT16(1);