summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Lane2017-06-26 14:31:10 +0000
committerTom Lane2017-06-26 14:31:10 +0000
commit00c5e511b94059396150c406f5d71598034a2061 (patch)
tree88acefe1bcff0b123d45e3b1dee34c0c531d428d
parent59cd3987afd61191483a4cfe8f6a0abfb8c878d6 (diff)
Minor code review for parse_phrase_operator().
Fix its header comment, which described the old behavior of the <N> phrase distance operator; we missed updating that in commit 028350f61. Also, reset errno before strtol() call, to defend against the possibility that it was already ERANGE at entry. (The lack of complaints says that it generally isn't, but this is at least a latent bug.) Very minor stylistic improvements as well. Victor Drobny noted the obsolete comment, I noted the errno issue. Back-patch to 9.6 where this code was added, just in case the errno issue is a live bug in some cases. Discussion: https://postgr.es/m/[email protected]
-rw-r--r--src/backend/utils/adt/tsquery.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/backend/utils/adt/tsquery.c b/src/backend/utils/adt/tsquery.c
index ee047bd8d5..fdb041971e 100644
--- a/src/backend/utils/adt/tsquery.c
+++ b/src/backend/utils/adt/tsquery.c
@@ -113,7 +113,7 @@ get_modifiers(char *buf, int16 *weight, bool *prefix)
* Parse phrase operator. The operator
* may take the following forms:
*
- * a <X> b (distance is no greater than X)
+ * a <N> b (distance is exactly N lexemes)
* a <-> b (default distance = 1)
*
* The buffer should begin with '<' char
@@ -129,10 +129,9 @@ parse_phrase_operator(char *buf, int16 *distance)
PHRASE_ERR,
PHRASE_FINISH
} state = PHRASE_OPEN;
-
char *ptr = buf;
char *endptr;
- long l = 1;
+ long l = 1; /* default distance */
while (*ptr)
{
@@ -151,16 +150,17 @@ parse_phrase_operator(char *buf, int16 *distance)
ptr++;
break;
}
- else if (!t_isdigit(ptr))
+ if (!t_isdigit(ptr))
{
state = PHRASE_ERR;
break;
}
+ errno = 0;
l = strtol(ptr, &endptr, 10);
if (ptr == endptr)
state = PHRASE_ERR;
- else if (errno == ERANGE || l > MAXENTRYPOS)
+ else if (errno == ERANGE || l < 0 || l > MAXENTRYPOS)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("distance in phrase operator should not be greater than %d",