fix(similarity): skip empty fingerprint sort - #1368
Conversation
Signed-off-by: wargloom <wargloom@gmail.com>
|
Thank you for this — and doubly so for reporting the issue and bringing the fix. This is exactly the shape a fix should have: one file, one guard, and a comment that explains the why rather than restating the code. The distinction you drew in #1367 is the right one — zero elements suppress comparator calls, but that has never made a null base a valid array pointer, and I checked the caller before merging: Merging. Thanks again for the care you put into both the report and the patch. |
|
One thing before I merge: this is still marked as a draft, so I have held off rather than promote it myself. If that is just left over from opening it, mark it ready (or say the word here) and it goes in as-is — the review above is complete and CI is 28/28 green. If instead you are still polishing something, take the time you need; there is no rush from our side and I would rather merge the version you consider finished. |
|
Thank you for the focused empty-fingerprint guard and for marking the PR ready. I have routed it at high priority in |
|
Thank you for this one — a textbook fix: exact scope, a clear rationale comment right at the call site, and an honest write-up of why the empty path violates the qsort contract even though every libc happens to tolerate it. The determinism contract for count >= 2 is untouched, so this is behavior-identical where it matters and strictly more correct where it doesn't. Much appreciated, as always! One note: we verified that no C-level assertion can bind this fix (the existing simhash suite already drives the empty path, but only a trap-on-UBSan build would ever fail without the guard). We're taking a follow-up on our side to bind it in the sanitizer lane so it can never silently regress. |
What changed
collect_fp_entries()now callsqsortonly when at least two fingerprintentries were collected.
Why
The empty path leaves
entries == NULL. Callingqsort(NULL, 0, ...)relies onlibrary behavior outside the portable array-pointer contract, while the
one-entry path needs no sorting at all. Guarding with
count > 1avoids bothunnecessary cases without changing deterministic ordering.
Fixes #1367.
Validation
scripts/build.sh— passedscripts/test.sh --suites simhash— passed, 24 sanitizer-backed testsgit diff --check— passedChecklist