Skip to content

Commit b6fe834

Browse files
authored
Merge pull request DeusData#1368 from WarGloom/agent/fix-empty-similarity-sort
fix(similarity): skip empty fingerprint sort
2 parents 66e9aec + 28fc4e2 commit b6fe834

1 file changed

Lines changed: 6 additions & 2 deletions

File tree

‎src/pipeline/pass_similarity.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,12 @@ static int collect_fp_entries(cbm_gbuf_t *gbuf, fp_entry_t **out_entries) {
148148
};
149149
}
150150
}
151-
/* Canonicalize (determinism) — see cmp_fp_entry_by_qn. */
152-
qsort(entries, (size_t)count, sizeof(fp_entry_t), cmp_fp_entry_by_qn);
151+
/* Canonicalize (determinism) — see cmp_fp_entry_by_qn. Avoid passing the
152+
* NULL empty-set buffer to qsort: libc treats zero elements as a no-op,
153+
* but the standard function contract still requires a valid base pointer. */
154+
if (count > 1) {
155+
qsort(entries, (size_t)count, sizeof(fp_entry_t), cmp_fp_entry_by_qn);
156+
}
153157
*out_entries = entries;
154158
return count;
155159
}

0 commit comments

Comments
 (0)