From fcec862f85277189664d8b483c0a9fce22e38eda Mon Sep 17 00:00:00 2001 From: pranav jain Date: Tue, 24 Dec 2024 19:04:27 +0000 Subject: [PATCH] addressing comments Signed-off-by: pranav jain --- contrib/babelfishpg_tsql/src/pltsql_coerce.c | 12 ++++------- contrib/babelfishpg_tsql/src/string.c | 21 +++++++++++--------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/contrib/babelfishpg_tsql/src/pltsql_coerce.c b/contrib/babelfishpg_tsql/src/pltsql_coerce.c index b8a3b28048..432e90d1a0 100644 --- a/contrib/babelfishpg_tsql/src/pltsql_coerce.c +++ b/contrib/babelfishpg_tsql/src/pltsql_coerce.c @@ -1403,15 +1403,11 @@ tsql_func_select_candidate_for_special_func(List *names, int nargs, Oid *input_t /* multiple suitable candidates with same return type should not exist in sys schema. */ else if (ncandidates > 1) { - if(OidIsValid(expr_result_type)) - ereport(ERROR, - (errcode(ERRCODE_INTERNAL_ERROR), - errmsg("multiple definitions of function %s.%s with return type %s found.", proc_nsname, proc_name, format_type_be(expr_result_type)))); - else if(OidIsValid(expr_arg_type)) - ereport(ERROR, - (errcode(ERRCODE_INTERNAL_ERROR), - errmsg("multiple definitions of function %s.%s with second arg type %s found.", proc_nsname, proc_name, format_type_be(expr_arg_type)))); + ereport(ERROR, + (errcode(ERRCODE_INTERNAL_ERROR), + errmsg("multiple definitions of function %s.%s with return type %s found.", proc_nsname, proc_name, format_type_be(expr_result_type)))); + } if (best_candidate != NULL) diff --git a/contrib/babelfishpg_tsql/src/string.c b/contrib/babelfishpg_tsql/src/string.c index e9af7c6d41..b3cbc4269e 100644 --- a/contrib/babelfishpg_tsql/src/string.c +++ b/contrib/babelfishpg_tsql/src/string.c @@ -56,36 +56,34 @@ static Datum return_varchar_pointer(char *buf, int size); Datum hashbytes(PG_FUNCTION_ARGS) { - Oid input_type = get_fn_expr_argtype(fcinfo->flinfo,1); + Oid input_type = get_fn_expr_argtype(fcinfo->flinfo,1); const char *algorithm = text_to_cstring(PG_GETARG_TEXT_P(0)); bytea *in = PG_GETARG_BYTEA_PP(1); size_t len = VARSIZE_ANY_EXHDR(in); + const uint8 *data = (unsigned char *) VARDATA_ANY(in); bytea *result; - unsigned char *data = (unsigned char *) VARDATA_ANY(in); - StringInfoData utf16_data; + StringInfoData utf16_data; /* * If the input_type is nvarchar then we convert it to UTF-16 encoding */ + initStringInfo(&utf16_data); if(((*common_utility_plugin_ptr->is_tsql_nvarchar_datatype)(input_type))) { - unsigned char *temp_data; - initStringInfo(&utf16_data); (common_utility_plugin_ptr->TsqlUTF8toUTF16StringInfo)(&utf16_data, data, len); len = utf16_data.len; - temp_data = (unsigned char *)palloc(len); - memcpy(temp_data,utf16_data.data,len); - data = temp_data; - pfree(utf16_data.data); + data = (const uint8 *)utf16_data.data; } if (strcasecmp(algorithm, "MD2") == 0) { + pfree(utf16_data.data); PG_RETURN_NULL(); } else if (strcasecmp(algorithm, "MD4") == 0) { + pfree(utf16_data.data); PG_RETURN_NULL(); } else if (strcasecmp(algorithm, "MD5") == 0) @@ -105,6 +103,7 @@ hashbytes(PG_FUNCTION_ARGS) SET_VARSIZE(result, sizeof(buf) + VARHDRSZ); memcpy(VARDATA(result), buf, sizeof(buf)); + pfree(utf16_data.data); PG_RETURN_BYTEA_P(result); } @@ -119,6 +118,7 @@ hashbytes(PG_FUNCTION_ARGS) SET_VARSIZE(result, sizeof(buf) + VARHDRSZ); memcpy(VARDATA(result), buf, sizeof(buf)); + pfree(utf16_data.data); PG_RETURN_BYTEA_P(result); } @@ -139,6 +139,7 @@ hashbytes(PG_FUNCTION_ARGS) SET_VARSIZE(result, sizeof(buf) + VARHDRSZ); memcpy(VARDATA(result), buf, sizeof(buf)); + pfree(utf16_data.data); PG_RETURN_BYTEA_P(result); } @@ -152,11 +153,13 @@ hashbytes(PG_FUNCTION_ARGS) SET_VARSIZE(result, sizeof(buf) + VARHDRSZ); memcpy(VARDATA(result), buf, sizeof(buf)); + pfree(utf16_data.data); PG_RETURN_BYTEA_P(result); } else { + pfree(utf16_data.data); PG_RETURN_NULL(); } }