Ranier Vilela <ranier...@gmail.com> writes: > Em seg., 14 de set. de 2020 às 10:53, Daniel Gustafsson <dan...@yesql.se> > escreveu: >> If the objection is that an unsigned var is tested with <= 0, then >> changing the >> semantics of the function seems a rather drastic solution:
> But if wchar2char must be follow wcstombs_l API. > wchar2char all calls must be: > result = wchar2char(); > if (result == 0 || result == (size_t)-1) { > See at lowerstr_with_len (src/backend/tsearch/ts_locale.c): Actually, lowerstr_with_len is perfectly fine. It's coercing the size_t result to int, so (size_t) -1 becomes integer -1 and its error check for wlen < 0 is correct. It might have a problem if the coercion to int could overflow, but that cannot happen because of our restrictions on the size of a palloc'd chunk. There are some other call sites that are failing to check at all, which is not so good. But changing the function's API to be both nonstandard and ambiguous (because a zero result is a perfectly valid case) doesn't help fix that. I concur with Daniel that none of the changes shown here are worthwhile improvements. It's not illegal to test an unsigned variable for "x <= 0". regards, tom lane