hashtext: fix fragile code. Previously, in the path for non-deterministic collations, the code assumed that bsize==rsize. That assumption seems to be true for ICU, and all non-deterministic collations are ICU, so it's not known to be an actual bug.
The only known place where bsize may not equal rsize is in the libc provider, where strxfrm() can return an upper bound of the size needed to store the result. That means the initial call to determine the buffer size (with dest==NULL, n==0) could return a larger number than the actual call with an adequate dest buffer. That's OK, because libc locales are always deterministic. Commit 679c5084cf2 partially fixed the assumption, but missed this part. Fix it, and add a more prominent documentation note. Reviewed-by: Haibo Yan <[email protected]> Discussion: https://postgr.es/m/CABXr29Hb31nkj1g2Jmk+1BhAm=3ecgs_pwy4tu++j8cqbnb...@mail.gmail.com Backpatch-through: 16 Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/aa655f88f71bc747083a4c7e04b6294ff6d19da6 Modified Files -------------- src/backend/access/hash/hashfunc.c | 4 ++-- src/backend/utils/adt/pg_locale.c | 8 +++++--- src/backend/utils/adt/pg_locale_libc.c | 10 ++++++++++ src/backend/utils/adt/varchar.c | 4 ++-- 4 files changed, 19 insertions(+), 7 deletions(-)
