Hi all,
In metaphone() we do the following:
/* return an empty string if we receive one */
if (!(str_i_len 0))
PG_RETURN_TEXT_P(cstring_to_text());
if (str_i_len MAX_METAPHONE_STRLEN)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg(argument exceeds the maximum
length of %d bytes,
MAX_METAPHONE_STRLEN)));
if (!(str_i_len 0))
ereport(ERROR,
(errcode(ERRCODE_ZERO_LENGTH_CHARACTER_STRING),
errmsg(argument is empty string)));
As we already return an empty string if the first condition is
satisfied, the third condition will never be satisfied. Returning an
empty string when output string is NULL has been introduced in commit
13629df of 2004, so I think that we should simply remove the code
block that will never be crossed, as in the patch attached.
Coverity has pointed out this issue.
Regards,
--
Michael
diff --git a/contrib/fuzzystrmatch/fuzzystrmatch.c b/contrib/fuzzystrmatch/fuzzystrmatch.c
index b48edb0..f9508a5 100644
--- a/contrib/fuzzystrmatch/fuzzystrmatch.c
+++ b/contrib/fuzzystrmatch/fuzzystrmatch.c
@@ -280,11 +280,6 @@ metaphone(PG_FUNCTION_ARGS)
errmsg(argument exceeds the maximum length of %d bytes,
MAX_METAPHONE_STRLEN)));
- if (!(str_i_len 0))
- ereport(ERROR,
-(errcode(ERRCODE_ZERO_LENGTH_CHARACTER_STRING),
- errmsg(argument is empty string)));
-
reqlen = PG_GETARG_INT32(1);
if (reqlen MAX_METAPHONE_STRLEN)
ereport(ERROR,
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers