Fixed buffer size for empty sparsevec with max dimensions (no impact to users due to Postgres allocation alignment) [skip ci]

Co-authored-by: 0xJi3F
(cherry picked from commit 5ffa6d022b211c89bb69bfd1d91cafbfeac8345a)
This commit is contained in:
Andrew Kane
2026-09-11 13:47:34 -07:00
committed by zeekay
parent a91f1c4c89
commit c3f4fed396
3 changed files with 9 additions and 2 deletions
+2 -2
View File
@@ -434,13 +434,13 @@ sparsevec_out(PG_FUNCTION_ARGS)
* nnz * (FLOAT_SHORTEST_DECIMAL_LEN - 1) bytes for
* float_to_shortest_decimal_bufn
*
* nnz - 1 bytes for ,
* max(nnz - 1, 0) bytes for ,
*
* 10 bytes for dimensions
*
* 4 bytes for {, }, /, and \0
*/
buf = (char *) palloc((11 + FLOAT_SHORTEST_DECIMAL_LEN) * sparsevec->nnz + 13);
buf = (char *) palloc((11 + FLOAT_SHORTEST_DECIMAL_LEN) * sparsevec->nnz + 14);
ptr = buf;
AppendChar(ptr, '{');
+6
View File
@@ -187,6 +187,12 @@ SELECT '{}/-1'::sparsevec;
ERROR: sparsevec must have at least 1 dimension
LINE 1: SELECT '{}/-1'::sparsevec;
^
SELECT '{}/1000000000'::sparsevec;
sparsevec
---------------
{}/1000000000
(1 row)
SELECT '{}/1000000001'::sparsevec;
ERROR: sparsevec cannot have more than 1000000000 dimensions
LINE 1: SELECT '{}/1000000001'::sparsevec;
+1
View File
@@ -38,6 +38,7 @@ SELECT '{1:1,1:1}/2'::sparsevec;
SELECT '{1:1,2:1,1:1}/2'::sparsevec;
SELECT '{}/5'::sparsevec;
SELECT '{}/-1'::sparsevec;
SELECT '{}/1000000000'::sparsevec;
SELECT '{}/1000000001'::sparsevec;
SELECT '{}/2147483648'::sparsevec;
SELECT '{}/-2147483649'::sparsevec;