pgvector.git / summary / log / commit / refs
commit cf570810eb3f08ee7cf625dbe7dfc8650d507f8e
Author: Andrew Kane <andrew@ankane.org>
Date: Wed Apr 17 07:05:31 2024 +0000
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 0350e9b4..e9274689 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);
}
/*
[parent: c361f8046547]