From f560d9987f27b01611c27580a188b0543f1f1492 Mon Sep 17 00:00:00 2001 From: Alexander Korotkov Date: Thu, 26 Oct 2017 13:42:29 +0300 Subject: [PATCH] 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. --- expected/jsquery.out | 6 ++++++ jsquery_io.c | 5 ++++- sql/jsquery.sql | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/expected/jsquery.out b/expected/jsquery.out index 14b2730..afb988d 100644 --- a/expected/jsquery.out +++ b/expected/jsquery.out @@ -1656,6 +1656,12 @@ select '{"a":{"aa":1}, "b":{"aa":1, "bb":2}}' @@ '*: (not $ is object or $.aa is t (1 row) +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; + jsquery +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- + "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) +(1 row) + select '[]' @@ '(@# > 0 and #: = 16)'::jsquery; ?column? ---------- diff --git a/jsquery_io.c b/jsquery_io.c index 8a43e8e..a295244 100644 --- a/jsquery_io.c +++ b/jsquery_io.c @@ -135,7 +135,10 @@ flattenJsQueryParseItem(StringInfo buf, JsQueryParseItem *item, bool onlyCurrent } if (item->next) - *(int32*)(buf->data + next) = flattenJsQueryParseItem(buf, item->next, onlyCurrentInPath); + { + chld = flattenJsQueryParseItem(buf, item->next, onlyCurrentInPath); + *(int32*)(buf->data + next) = chld; + } return pos; } diff --git a/sql/jsquery.sql b/sql/jsquery.sql index f4f461c..fb5319a 100644 --- a/sql/jsquery.sql +++ b/sql/jsquery.sql @@ -331,6 +331,7 @@ select '{"a":{"aa":1}, "b":{"aa":1, "bb":2}}' @@ '%:.aa is numeric'::jsquery; select '{"a":{"aa":1}, "b":{"aa":true, "bb":2}}' @@ '%:.aa is numeric'::jsquery; select '{"a":{"aa":1}, "b":{"aa":1, "bb":2}, "aa":16}' @@ '*: (not $ is object or $.aa is numeric)'::jsquery; select '{"a":{"aa":1}, "b":{"aa":1, "bb":2}}' @@ '*: (not $ is object or $.aa is numeric or % is object)'::jsquery; +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; select '[]' @@ '(@# > 0 and #: = 16)'::jsquery; select '[16]' @@ '(@# > 0 and #: = 16)'::jsquery;