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/
2b5382fdff9b1f79d5eb2c99c4d2cbe2@postgrespro.ru
* 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
PHRASE_ERR,
PHRASE_FINISH
} state = PHRASE_OPEN;
-
char *ptr = buf;
char *endptr;
- long l = 1;
+ long l = 1; /* default distance */
while (*ptr)
{
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",