diff --git a/src/ivfbuild.c b/src/ivfbuild.c index e927468..0350e9b 100644 --- a/src/ivfbuild.c +++ b/src/ivfbuild.c @@ -337,20 +337,14 @@ GetMaxDimensions(IvfflatType type) static Size GetItemSize(IvfflatType type, int dimensions) { - Size size; - if (type == IVFFLAT_TYPE_VECTOR) - size = VECTOR_SIZE(dimensions); + return VECTOR_SIZE(dimensions); else if (type == IVFFLAT_TYPE_HALFVEC) - size = HALFVEC_SIZE(dimensions); + return HALFVEC_SIZE(dimensions); else if (type == IVFFLAT_TYPE_BIT) - size = VARBITTOTALLEN(dimensions); + return VARBITTOTALLEN(dimensions); else elog(ERROR, "Unsupported type"); - - /* Ensure items are aligned to prevent UB */ - /* Only need 4 byte alignment, but prefer MAXALIGN */ - return MAXALIGN(size); } /* diff --git a/src/ivfutils.c b/src/ivfutils.c index 26e085d..3fdcba9 100644 --- a/src/ivfutils.c +++ b/src/ivfutils.c @@ -18,6 +18,9 @@ VectorArrayInit(int maxlen, int dimensions, Size itemsize) { VectorArray res = palloc(sizeof(VectorArrayData)); + /* Ensure items are aligned to prevent UB */ + itemsize = MAXALIGN(itemsize); + res->length = 0; res->maxlen = maxlen; res->dim = dimensions;