Re: Undefined behavior detected by new clang's ubsan
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: John Naylor <johncnaylorls@gmail.com>
Cc: Alexander Lakhin <exclusion@gmail.com>,
pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2026-01-20T18:52:08Z
Lists: pgsql-hackers
John Naylor <johncnaylorls@gmail.com> writes: > I don't think it's great to pass a NULL pointer to a sort, but the > length could conceivably be zero for future degenerate cases, so we > could silence the warning by adding "if (n < 2) return;" before the > for-loop. The advantage of doing that anyway is it allows us to remove > all four of the "if (d_ > ST_POINTER_STEP)" branches in the recursion > part. That's better for readability. +1 regards, tom lane
Commits
-
Future-proof sort template against undefined behavior
- 7467041cde9e 19 (unreleased) landed
-
Fix various instances of undefined behavior
- 176dffdf7d2a 19 (unreleased) landed
- fc56793c9ae5 14.21 landed
- b5e1cd2fdca1 18.2 landed
- 73ac2b37401d 16.12 landed
- 6b81a1c7c905 15.16 landed
- 1662cd0cb7ae 17.8 landed