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 ------ REL_17_STABLE Details ------- https://git.postgresql.org/pg/commitdiff/e2a44c77112c76113dad8dd6e99bddd91250f6c4 Modified Files -------------- src/backend/access/hash/hashfunc.c | 4 ++-- src/backend/utils/adt/pg_locale.c | 24 +++++++++++++++++++++--- src/backend/utils/adt/varchar.c | 4 ++-- 3 files changed, 25 insertions(+), 7 deletions(-)
