mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-12 07:36:55 +08:00
Ensure items are always aligned
This commit is contained in:
@@ -337,20 +337,14 @@ GetMaxDimensions(IvfflatType type)
|
|||||||
static Size
|
static Size
|
||||||
GetItemSize(IvfflatType type, int dimensions)
|
GetItemSize(IvfflatType type, int dimensions)
|
||||||
{
|
{
|
||||||
Size size;
|
|
||||||
|
|
||||||
if (type == IVFFLAT_TYPE_VECTOR)
|
if (type == IVFFLAT_TYPE_VECTOR)
|
||||||
size = VECTOR_SIZE(dimensions);
|
return VECTOR_SIZE(dimensions);
|
||||||
else if (type == IVFFLAT_TYPE_HALFVEC)
|
else if (type == IVFFLAT_TYPE_HALFVEC)
|
||||||
size = HALFVEC_SIZE(dimensions);
|
return HALFVEC_SIZE(dimensions);
|
||||||
else if (type == IVFFLAT_TYPE_BIT)
|
else if (type == IVFFLAT_TYPE_BIT)
|
||||||
size = VARBITTOTALLEN(dimensions);
|
return VARBITTOTALLEN(dimensions);
|
||||||
else
|
else
|
||||||
elog(ERROR, "Unsupported type");
|
elog(ERROR, "Unsupported type");
|
||||||
|
|
||||||
/* Ensure items are aligned to prevent UB */
|
|
||||||
/* Only need 4 byte alignment, but prefer MAXALIGN */
|
|
||||||
return MAXALIGN(size);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -18,6 +18,9 @@ VectorArrayInit(int maxlen, int dimensions, Size itemsize)
|
|||||||
{
|
{
|
||||||
VectorArray res = palloc(sizeof(VectorArrayData));
|
VectorArray res = palloc(sizeof(VectorArrayData));
|
||||||
|
|
||||||
|
/* Ensure items are aligned to prevent UB */
|
||||||
|
itemsize = MAXALIGN(itemsize);
|
||||||
|
|
||||||
res->length = 0;
|
res->length = 0;
|
||||||
res->maxlen = maxlen;
|
res->maxlen = maxlen;
|
||||||
res->dim = dimensions;
|
res->dim = dimensions;
|
||||||
|
|||||||
Reference in New Issue
Block a user