From 745a411858c47c215ee89e41fa36a58a6d7d5c6b Mon Sep 17 00:00:00 2001 From: Ziya Kapoor Date: Tue, 27 Oct 2026 22:27:57 +0530 Subject: [PATCH] sas7bcat: compare block pointers three-way instead of subtracting --- src/sas/readstat_sas7bcat_read.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/sas/readstat_sas7bcat_read.c b/src/sas/readstat_sas7bcat_read.c index 4ded002f..9659d326 100644 --- a/src/sas/readstat_sas7bcat_read.c +++ b/src/sas/readstat_sas7bcat_read.c @@ -296,7 +296,10 @@ static readstat_error_t sas7bcat_augment_index(const char *index, size_t len, sa static int compare_block_pointers(const void *elem1, const void *elem2) { uint64_t v1 = *(const uint64_t *)elem1; uint64_t v2 = *(const uint64_t *)elem2; - return v1 - v2; + /* The values pack a page number into the high 32 bits, so a plain + * subtraction truncated to int loses that half and misorders (or reports + * as equal) pointers on different pages. Compare three-way instead. */ + return (v1 > v2) - (v1 < v2); } static void sas7bcat_sort_index(sas7bcat_ctx_t *ctx) {