mirror of
https://git.postgresql.org/git/postgresql.git
synced 2025-01-12 18:34:36 +08:00
Fix alignment in multirange_get_range() function
The multirange_get_range() function fails when two boundaries of the same range have different alignments. Fix that by adding proper pointer alignment. Reported-by: Alexander Lakhin Discussion: https://postgr.es/m/17300-dced2d01ddeb1f2f%40postgresql.org Backpatch-through: 14
This commit is contained in:
parent
c8b733c4c4
commit
5cc9c83740
@ -713,7 +713,10 @@ multirange_get_range(TypeCacheEntry *rangetyp,
|
||||
if (RANGE_HAS_LBOUND(flags))
|
||||
ptr = (Pointer) att_addlength_pointer(ptr, typlen, ptr);
|
||||
if (RANGE_HAS_UBOUND(flags))
|
||||
{
|
||||
ptr = (Pointer) att_align_pointer(ptr, typalign, typlen, ptr);
|
||||
ptr = (Pointer) att_addlength_pointer(ptr, typlen, ptr);
|
||||
}
|
||||
len = (ptr - begin) + sizeof(RangeType) + sizeof(uint8);
|
||||
|
||||
range = palloc0(len);
|
||||
|
@ -97,6 +97,12 @@ select ' {( " a " " a ", " z " " z " ) }'::textmultirange;
|
||||
{(" a a "," z z ")}
|
||||
(1 row)
|
||||
|
||||
select textrange('\\\\', repeat('a', 200))::textmultirange;
|
||||
textrange
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
{["\\\\\\\\",aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)}
|
||||
(1 row)
|
||||
|
||||
select '{(,z)}'::textmultirange;
|
||||
textmultirange
|
||||
----------------
|
||||
@ -289,10 +295,10 @@ select textmultirange(textrange('a', 'c'), textrange('f', 'g'));
|
||||
{[a,c),[f,g)}
|
||||
(1 row)
|
||||
|
||||
select textmultirange(textrange('a', 'c'), textrange('b', 'd'));
|
||||
textmultirange
|
||||
----------------
|
||||
{[a,d)}
|
||||
select textmultirange(textrange('\\\\', repeat('a', 200)), textrange('c', 'd'));
|
||||
textmultirange
|
||||
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
{["\\\\\\\\",aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa),[c,d)}
|
||||
(1 row)
|
||||
|
||||
--
|
||||
@ -363,6 +369,13 @@ select unnest(textmultirange(textrange('a', 'b'), textrange('d', 'e')));
|
||||
[d,e)
|
||||
(2 rows)
|
||||
|
||||
select unnest(textmultirange(textrange('\\\\', repeat('a', 200)), textrange('c', 'd')));
|
||||
unnest
|
||||
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
||||
["\\\\\\\\",aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)
|
||||
[c,d)
|
||||
(2 rows)
|
||||
|
||||
--
|
||||
-- create some test data and test the operators
|
||||
--
|
||||
|
@ -72,12 +72,6 @@ select ' ( " a " " a ", " z " " z " ) '::textrange;
|
||||
(" a a "," z z ")
|
||||
(1 row)
|
||||
|
||||
select '(,z)'::textrange;
|
||||
textrange
|
||||
-----------
|
||||
(,z)
|
||||
(1 row)
|
||||
|
||||
select '(a,)'::textrange;
|
||||
textrange
|
||||
-----------
|
||||
|
@ -25,6 +25,7 @@ select '{}'::textmultirange;
|
||||
select ' {} '::textmultirange;
|
||||
select ' { empty, empty } '::textmultirange;
|
||||
select ' {( " a " " a ", " z " " z " ) }'::textmultirange;
|
||||
select textrange('\\\\', repeat('a', 200))::textmultirange;
|
||||
select '{(,z)}'::textmultirange;
|
||||
select '{(a,)}'::textmultirange;
|
||||
select '{[,z]}'::textmultirange;
|
||||
@ -63,7 +64,7 @@ select '{(a,a)}'::textmultirange;
|
||||
select textmultirange();
|
||||
select textmultirange(textrange('a', 'c'));
|
||||
select textmultirange(textrange('a', 'c'), textrange('f', 'g'));
|
||||
select textmultirange(textrange('a', 'c'), textrange('b', 'd'));
|
||||
select textmultirange(textrange('\\\\', repeat('a', 200)), textrange('c', 'd'));
|
||||
|
||||
--
|
||||
-- test casts, both a built-in range type and a user-defined one:
|
||||
@ -82,6 +83,7 @@ select textrange(null, null)::textmultirange;
|
||||
--
|
||||
select unnest(int4multirange(int4range('5', '6'), int4range('1', '2')));
|
||||
select unnest(textmultirange(textrange('a', 'b'), textrange('d', 'e')));
|
||||
select unnest(textmultirange(textrange('\\\\', repeat('a', 200)), textrange('c', 'd')));
|
||||
|
||||
--
|
||||
-- create some test data and test the operators
|
||||
|
@ -22,7 +22,6 @@ select '[z,a]'::textrange;
|
||||
select ' empty '::textrange;
|
||||
select ' ( empty, empty ) '::textrange;
|
||||
select ' ( " a " " a ", " z " " z " ) '::textrange;
|
||||
select '(,z)'::textrange;
|
||||
select '(a,)'::textrange;
|
||||
select '[,z]'::textrange;
|
||||
select '[a,]'::textrange;
|
||||
|
Loading…
Reference in New Issue
Block a user