diff options
| author | Tom Lane <tgl@sss.pgh.pa.us> | 2025-11-01 13:25:42 -0400 |
|---|---|---|
| committer | Tom Lane <tgl@sss.pgh.pa.us> | 2025-11-01 13:25:42 -0400 |
| commit | ff8aba65d463b144db7c081181b5ccf6eaaf1af4 (patch) | |
| tree | 7415692122eeb385d663f0117fa370ea0db61154 /contrib/ltree/ltree_op.c | |
| parent | 2648eab3779b0204368f785f9df84de01270e537 (diff) | |
Fix contrib/ltree's subpath() with negative offset.
subpath(ltree,offset,len) now correctly errors when given an offset
less than -n, where n is the number of labels in the given ltree.
There was a duplicate block of code that allowed an offset as low
as -2n. The documentation says no such thing, so this must have
been a copy-and-paste error in the original ltree patch.
While here, avoid redundant calculation of "end" and write
LTREE_MAX_LEVELS rather than its hard-coded value.
Author: Marcus Gartner <m.a.gartner@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAAUGV_SvBO9gWYbaejb9nhe-mS9FkNP4QADNTdM3wdRhvLobwA@mail.gmail.com
Diffstat (limited to 'contrib/ltree/ltree_op.c')
| -rw-r--r-- | contrib/ltree/ltree_op.c | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/contrib/ltree/ltree_op.c b/contrib/ltree/ltree_op.c index ce9f4caad4f..e3a84db37ff 100644 --- a/contrib/ltree/ltree_op.c +++ b/contrib/ltree/ltree_op.c @@ -316,23 +316,15 @@ subpath(PG_FUNCTION_ARGS) int32 end; ltree *res; - end = start + len; - - if (start < 0) - { - start = t->numlevel + start; - end = start + len; - } if (start < 0) - { /* start > t->numlevel */ start = t->numlevel + start; - end = start + len; - } if (len < 0) end = t->numlevel + len; else if (len == 0) - end = (fcinfo->nargs == 3) ? start : 0xffff; + end = (fcinfo->nargs == 3) ? start : LTREE_MAX_LEVELS; + else + end = start + len; res = inner_subltree(t, start, end); |
