Skip to content

Commit

Permalink
Update varbinaryvarchar C function to read typmod only when the numbe…
Browse files Browse the repository at this point in the history
…r of arguments are more than 1
  • Loading branch information
basasairohan committed Jan 2, 2024
1 parent 876c01a commit 209a6e0
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions contrib/babelfishpg_common/src/varbinary.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ PG_FUNCTION_INFO_V1(rowversionvarbinary);
PG_FUNCTION_INFO_V1(varcharvarbinary);
PG_FUNCTION_INFO_V1(bpcharvarbinary);
PG_FUNCTION_INFO_V1(varbinaryvarchar);
PG_FUNCTION_INFO_V1(varbinaryvarchar_deprecated_2_6_0);
PG_FUNCTION_INFO_V1(varcharbinary);
PG_FUNCTION_INFO_V1(bpcharbinary);
PG_FUNCTION_INFO_V1(varcharrowversion);
Expand Down Expand Up @@ -722,8 +723,6 @@ bpcharvarbinary(PG_FUNCTION_ARGS)
PG_RETURN_BYTEA_P(result);
}



Datum
varbinaryvarchar(PG_FUNCTION_ARGS)
{
Expand All @@ -732,12 +731,18 @@ varbinaryvarchar(PG_FUNCTION_ARGS)
VarChar *result;
char *encoded_result;
size_t len = VARSIZE_ANY_EXHDR(source);
int32 typmod = PG_GETARG_INT32(1);
int32 maxlen = typmod - VARHDRSZ;
int32 typmod = -1;
int32 maxlen = -1;
coll_info collInfo;
int encodedByteLen;
MemoryContext ccxt = CurrentMemoryContext;

if (fcinfo->nargs > 1)
{
typmod = PG_GETARG_INT32(1);
maxlen = typmod - VARHDRSZ;
}

/*
* Allow trailing null bytes
* Its safe since multi byte UTF-8 does not contain 0x00
Expand Down

0 comments on commit 209a6e0

Please sign in to comment.