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. |
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