Ensure items are always aligned

This commit is contained in:
Andrew Kane
2024-04-17 00:17:40 -07:00
parent cf570810eb
commit 576a37e975
2 changed files with 6 additions and 9 deletions

View File

@@ -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);
}
/*

View File

@@ -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;