|
15 | 15 | *
|
16 | 16 | *
|
17 | 17 | * IDENTIFICATION
|
18 |
| - * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.155 2004/01/17 20:09:35 tgl Exp $ |
| 18 | + * $PostgreSQL: pgsql/src/backend/utils/adt/selfuncs.c,v 1.156 2004/02/02 03:07:08 tgl Exp $ |
19 | 19 | *
|
20 | 20 | *-------------------------------------------------------------------------
|
21 | 21 | */
|
@@ -3742,6 +3742,11 @@ pattern_selectivity(Const *patt, Pattern_Type ptype)
|
3742 | 3742 | *
|
3743 | 3743 | * This could be rather slow in the worst case, but in most cases we
|
3744 | 3744 | * won't have to try more than one or two strings before succeeding.
|
| 3745 | + * |
| 3746 | + * NOTE: at present this assumes we are in the C locale, so that simple |
| 3747 | + * bytewise comparison applies. However, we might be in a multibyte |
| 3748 | + * encoding such as UTF-8, so we do have to watch out for generating |
| 3749 | + * invalid encoding sequences. |
3745 | 3750 | */
|
3746 | 3751 | Const *
|
3747 | 3752 | make_greater_string(const Const *str_const)
|
@@ -3788,13 +3793,20 @@ make_greater_string(const Const *str_const)
|
3788 | 3793 | /*
|
3789 | 3794 | * Try to generate a larger string by incrementing the last byte.
|
3790 | 3795 | */
|
3791 |
| - if (*lastchar < (unsigned char) 255) |
| 3796 | + while (*lastchar < (unsigned char) 255) |
3792 | 3797 | {
|
3793 | 3798 | Const *workstr_const;
|
3794 | 3799 |
|
3795 | 3800 | (*lastchar)++;
|
| 3801 | + |
3796 | 3802 | if (datatype != BYTEAOID)
|
| 3803 | + { |
| 3804 | + /* do not generate invalid encoding sequences */ |
| 3805 | + if (!pg_verifymbstr((const unsigned char *) workstr, |
| 3806 | + len, true)) |
| 3807 | + continue; |
3797 | 3808 | workstr_const = string_to_const(workstr, datatype);
|
| 3809 | + } |
3798 | 3810 | else
|
3799 | 3811 | workstr_const = string_to_bytea_const(workstr, len);
|
3800 | 3812 |
|
|
0 commit comments