Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 00c5e51

Browse files
committed
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 028350f. 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
1 parent 59cd398 commit 00c5e51

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/backend/utils/adt/tsquery.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ get_modifiers(char *buf, int16 *weight, bool *prefix)
113113
* Parse phrase operator. The operator
114114
* may take the following forms:
115115
*
116-
* a <X> b (distance is no greater than X)
116+
* a <N> b (distance is exactly N lexemes)
117117
* a <-> b (default distance = 1)
118118
*
119119
* The buffer should begin with '<' char
@@ -129,10 +129,9 @@ parse_phrase_operator(char *buf, int16 *distance)
129129
PHRASE_ERR,
130130
PHRASE_FINISH
131131
} state = PHRASE_OPEN;
132-
133132
char *ptr = buf;
134133
char *endptr;
135-
long l = 1;
134+
long l = 1; /* default distance */
136135

137136
while (*ptr)
138137
{
@@ -151,16 +150,17 @@ parse_phrase_operator(char *buf, int16 *distance)
151150
ptr++;
152151
break;
153152
}
154-
else if (!t_isdigit(ptr))
153+
if (!t_isdigit(ptr))
155154
{
156155
state = PHRASE_ERR;
157156
break;
158157
}
159158

159+
errno = 0;
160160
l = strtol(ptr, &endptr, 10);
161161
if (ptr == endptr)
162162
state = PHRASE_ERR;
163-
else if (errno == ERANGE || l > MAXENTRYPOS)
163+
else if (errno == ERANGE || l < 0 || l > MAXENTRYPOS)
164164
ereport(ERROR,
165165
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
166166
errmsg("distance in phrase operator should not be greater than %d",

0 commit comments

Comments
 (0)