Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit00c5e51

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 commit028350f.Also, reset errno before strtol() call, to defend against the possibilitythat it was already ERANGE at entry. (The lack of complaints says thatit generally isn't, but this is at least a latent bug.) Very minorstylistic 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 errnoissue is a live bug in some cases.Discussion:https://postgr.es/m/2b5382fdff9b1f79d5eb2c99c4d2cbe2@postgrespro.ru
1 parent59cd398 commit00c5e51

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 isno greater than X)
116+
*a <N> b (distance isexactly 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-
longl=1;
134+
longl=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-
elseif (!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-
elseif (errno==ERANGE||l>MAXENTRYPOS)
163+
elseif (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)

[8]ページ先頭

©2009-2025 Movatter.jp