mirror of
https://github.com/pgvector/pgvector.git
synced 2026-07-11 15:16:54 +08:00
Hardened VectorArrayInit
This commit is contained in:
@@ -23,11 +23,15 @@
|
|||||||
VectorArray
|
VectorArray
|
||||||
VectorArrayInit(int maxlen, int dimensions, Size itemsize)
|
VectorArrayInit(int maxlen, int dimensions, Size itemsize)
|
||||||
{
|
{
|
||||||
VectorArray res = palloc(sizeof(VectorArrayData));
|
VectorArray res;
|
||||||
|
|
||||||
|
if (maxlen < 1 || dimensions < 1)
|
||||||
|
elog(ERROR, "safety check failed");
|
||||||
|
|
||||||
/* Ensure items are aligned to prevent UB */
|
/* Ensure items are aligned to prevent UB */
|
||||||
itemsize = MAXALIGN(itemsize);
|
itemsize = MAXALIGN(itemsize);
|
||||||
|
|
||||||
|
res = palloc(sizeof(VectorArrayData));
|
||||||
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