Skip to content

Commit ee4301e

Browse files
daviesrobwhitwham
authored andcommitted
Simplify kh_grow_to_fit table size check
For some reason, early versions of clang incorrectly optimised a check to ensure that the number of buckets in a resized hash table will still fit in a khint_t, with the result that most of the function was replaced by "return -2". Fix by putting the limit value in a separate variable, so the comparison part no longer needs to do any type conversion.
1 parent afbd7f7 commit ee4301e

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

NEWS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ Updates
2828
* Consolidate and simplify SAM header parsing. This considerably speeds up
2929
parsing files with many SQ lines.
3030
(PR #1947. PR #1953 fixes oss-fuzz issues 444492071, 444492076, 444547724,
31-
444490034)
31+
444490034, PR #1977)
3232

3333
* Switch from strtol to hts_str2uint in mod parsing for speed increase.
3434
(PR #1957. Thanks to Chris Wright)

htslib/khash.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ static const double __ac_HASH_UPPER = 0.77;
311311
SCOPE int kh_grow_to_fit_##name(kh_##name##_t *h, khint_t n_items) \
312312
{ \
313313
khint_t n_buckets; \
314+
khint_t resize_limit = (khint_t) ((double) INT_MAX * __ac_HASH_UPPER); \
314315
if (n_items < h->upper_bound - h->size) { \
315316
/* Should be big enough ... */ \
316317
if (n_items < h->upper_bound - h->n_occupied) \
@@ -321,7 +322,7 @@ static const double __ac_HASH_UPPER = 0.77;
321322
if (UINT_MAX - h->size < n_items) \
322323
return -2; \
323324
n_items += h->size; \
324-
if (n_items >= INT_MAX * __ac_HASH_UPPER) \
325+
if (n_items >= resize_limit) \
325326
return -2; \
326327
n_buckets = n_items > 0 ? n_items : 1; \
327328
kroundup32(n_buckets); \

0 commit comments

Comments
 (0)