From cf570810eb3f08ee7cf625dbe7dfc8650d507f8e Mon Sep 17 00:00:00 2001 From: Andrew Kane Date: Wed, 17 Apr 2024 00:05:31 -0700 Subject: [PATCH] Fixed alignment for bit in IVFFlat - fixes #520 --- src/ivfbuild.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/ivfbuild.c b/src/ivfbuild.c index 0350e9b..e927468 100644 --- a/src/ivfbuild.c +++ b/src/ivfbuild.c @@ -337,14 +337,20 @@ GetMaxDimensions(IvfflatType type) static Size GetItemSize(IvfflatType type, int dimensions) { + Size size; + if (type == IVFFLAT_TYPE_VECTOR) - return VECTOR_SIZE(dimensions); + size = VECTOR_SIZE(dimensions); else if (type == IVFFLAT_TYPE_HALFVEC) - return HALFVEC_SIZE(dimensions); + size = HALFVEC_SIZE(dimensions); else if (type == IVFFLAT_TYPE_BIT) - return VARBITTOTALLEN(dimensions); + size = 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); } /*