Skip to content

Commit f560d99

Browse files
author
Alexander Korotkov
committed
Fix bug in assignment of next jsquery item offset.
Output buffer could be reallocated after next item is filled. So, we need to make sure that we calculate pointer inside the buffer after item is filled.
1 parent 2ead3ad commit f560d99

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

Diff for: expected/jsquery.out

+6
Original file line numberDiff line numberDiff line change
@@ -1656,6 +1656,12 @@ select '{"a":{"aa":1}, "b":{"aa":1, "bb":2}}' @@ '*: (not $ is object or $.aa is
16561656
t
16571657
(1 row)
16581658

1659+
SELECT 'test.# IN (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64)'::jsquery;
1660+
jsquery
1661+
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1662+
"test".# IN (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64)
1663+
(1 row)
1664+
16591665
select '[]' @@ '(@# > 0 and #: = 16)'::jsquery;
16601666
?column?
16611667
----------

Diff for: jsquery_io.c

+4-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,10 @@ flattenJsQueryParseItem(StringInfo buf, JsQueryParseItem *item, bool onlyCurrent
135135
}
136136

137137
if (item->next)
138-
*(int32*)(buf->data + next) = flattenJsQueryParseItem(buf, item->next, onlyCurrentInPath);
138+
{
139+
chld = flattenJsQueryParseItem(buf, item->next, onlyCurrentInPath);
140+
*(int32*)(buf->data + next) = chld;
141+
}
139142

140143
return pos;
141144
}

Diff for: sql/jsquery.sql

+1
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ select '{"a":{"aa":1}, "b":{"aa":1, "bb":2}}' @@ '%:.aa is numeric'::jsquery;
331331
select '{"a":{"aa":1}, "b":{"aa":true, "bb":2}}' @@ '%:.aa is numeric'::jsquery;
332332
select '{"a":{"aa":1}, "b":{"aa":1, "bb":2}, "aa":16}' @@ '*: (not $ is object or $.aa is numeric)'::jsquery;
333333
select '{"a":{"aa":1}, "b":{"aa":1, "bb":2}}' @@ '*: (not $ is object or $.aa is numeric or % is object)'::jsquery;
334+
SELECT 'test.# IN (1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47,48,49,50,51,52,53,54,55,56,57,58,59,60,61,62,63,64)'::jsquery;
334335

335336
select '[]' @@ '(@# > 0 and #: = 16)'::jsquery;
336337
select '[16]' @@ '(@# > 0 and #: = 16)'::jsquery;

0 commit comments

Comments
 (0)