Future-proof sort template against undefined behavior Commit 176dffdf7 added a NULL array pointer check before performing a qsort in order to prevent undefined behavior when passing NULL pointer and zero length. To head off future degenerate cases, check that there are at least two elements to sort before proceeding with insertion sort. This has the added advantage of allowing us to remove four equivalent checks that guarded against recursion/iteration.
There might be a tiny performance penalty from unproductive recursions, but we can buy that back by increasing the insertion sort threshold. That is left for future work. Discussion: https://postgr.es/m/CANWCAZZWvds_35nXc4vXD-eBQa_=mxVtqZf-PM_ps=sd7gh...@mail.gmail.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/7467041cde9ed1966cb3ea18da8ac119b462c2e4 Modified Files -------------- src/include/lib/sort_template.h | 40 +++++++++++++++++++++------------------- 1 file changed, 21 insertions(+), 19 deletions(-)
