This is an automated email from the ASF dual-hosted git repository. okislal pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/madlib.git
commit 32efa598196c4f5da01910f576304312c7bfae41 Author: Orhan Kislal <[email protected]> AuthorDate: Tue Mar 3 19:04:19 2020 -0500 MFVSketch: Use datumIsEqual for comparing datums mfvsketch used memcmp() for comparing two Datums to check for equality. There is a note in the postgres/gpdb source saying this is unsafe, so we converted it over to calling the postgres function datumIsEqual() which can handle either little-endian or big-endian byte order, making it more portable. Co-authored-by: Domino Valdano <[email protected]> --- methods/sketch/src/pg_gp/mfvsketch.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/methods/sketch/src/pg_gp/mfvsketch.c b/methods/sketch/src/pg_gp/mfvsketch.c index 0b954cc..f1853e7 100644 --- a/methods/sketch/src/pg_gp/mfvsketch.c +++ b/methods/sketch/src/pg_gp/mfvsketch.c @@ -35,6 +35,7 @@ #include <utils/lsyscache.h> #include <utils/numeric.h> #include <utils/typcache.h> +#include <utils/datum.h> #include <nodes/execnodes.h> #include <fmgr.h> #include <catalog/pg_type.h> @@ -179,10 +180,8 @@ int mfv_find(bytea *blob, Datum val) { mfvtransval *transval = (mfvtransval *)VARDATA(blob); unsigned i; - uint32 len; - void * datp; + void *datp; Datum iDat; - void *valp = DatumExtractPointer(val, transval->typByVal); /* look for existing entry for this value */ for (i = 0; i < transval->next_mfv; i++) { @@ -190,11 +189,9 @@ int mfv_find(bytea *blob, Datum val) datp = mfv_transval_getval(blob,i); iDat = PointerExtractDatum(datp, transval->typByVal); - if ((len = ExtractDatumLen(iDat, transval->typLen, transval->typByVal, -1)) - == ExtractDatumLen(val, transval->typLen, transval->typByVal, -1)) { - if (!memcmp(datp, valp, len)) - /* arg is an mfv */ - return(i); + if (datumIsEqual(iDat, val, transval->typByVal, transval->typLen)) { + /* arg is an mfv */ + return(i); } } return(-1);
