Skip to content

Commit 952926c

Browse files
committed
Use INT64_MAX
1 parent 4ce6c26 commit 952926c

File tree

2 files changed

+16
-17
lines changed

2 files changed

+16
-17
lines changed

hts.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,7 +2692,7 @@ const char *hts_parse_region(const char *s, int *tid, int64_t *beg, int64_t *end
26922692
if (!s || !tid || !beg || !end || !getid)
26932693
return NULL;
26942694

2695-
int s_len = strlen(s); // int is sufficient given beg/end types
2695+
size_t s_len = strlen(s);
26962696
kstring_t ks = { 0, 0, NULL };
26972697

26982698
const char *colon = NULL, *comma = NULL;
@@ -2741,7 +2741,7 @@ const char *hts_parse_region(const char *s, int *tid, int64_t *beg, int64_t *end
27412741

27422742
// No colon is simplest case; just check and return.
27432743
if (colon == NULL) {
2744-
*beg = 0; *end = INT_MAX;
2744+
*beg = 0; *end = INT64_MAX;
27452745
kputsn(s, s_len-quoted, &ks); // convert to nul terminated string
27462746
if (!ks.s) {
27472747
*tid = -1;
@@ -2756,7 +2756,7 @@ const char *hts_parse_region(const char *s, int *tid, int64_t *beg, int64_t *end
27562756

27572757
// Has a colon, but check whole name first.
27582758
if (!quoted) {
2759-
*beg = 0; *end = INT_MAX;
2759+
*beg = 0; *end = INT64_MAX;
27602760
kputsn(s, s_len, &ks); // convert to nul terminated string
27612761
if (!ks.s) {
27622762
*tid = -1;
@@ -2805,7 +2805,7 @@ const char *hts_parse_region(const char *s, int *tid, int64_t *beg, int64_t *end
28052805
if (*beg < 0) {
28062806
if (isdigit(*hyphen) || *hyphen == '\0' || *hyphen == ',') {
28072807
// interpret chr:-100 as chr:1-100
2808-
*end = *beg==-1 ? INT_MAX : -(*beg+1);
2808+
*end = *beg==-1 ? INT64_MAX : -(*beg+1);
28092809
*beg = 0;
28102810
return s_end;
28112811
} else if (*hyphen == '-') {
@@ -2817,7 +2817,7 @@ const char *hts_parse_region(const char *s, int *tid, int64_t *beg, int64_t *end
28172817
}
28182818

28192819
if (*hyphen == '\0' || ((flags & HTS_PARSE_LIST) && *hyphen == ',')) {
2820-
*end = flags & HTS_PARSE_ONE_COORD ? *beg+1 : INT_MAX;
2820+
*end = flags & HTS_PARSE_ONE_COORD ? *beg+1 : INT64_MAX;
28212821
} else if (*hyphen == '-') {
28222822
*end = hts_parse_decimal(hyphen+1, &hyphen, flags);
28232823
if (*hyphen != '\0' && *hyphen != ',') {
@@ -2830,7 +2830,7 @@ const char *hts_parse_region(const char *s, int *tid, int64_t *beg, int64_t *end
28302830
}
28312831

28322832
if (*end == 0)
2833-
*end = INT_MAX; // interpret chr:100- as chr:100-<end>
2833+
*end = INT64_MAX; // interpret chr:100- as chr:100-<end>
28342834

28352835
if (*beg >= *end) return NULL;
28362836

test/test-parse-reg.c

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,39 +87,38 @@ int reg_test(char *fn) {
8787
// 5 chr1,chr3
8888

8989
// Check range extensions.
90-
// NB: fix INT_MAX once we merge the 64-bit pos code.
91-
reg_expected(hdr, "chr1", 0, "", 0, 0, INT_MAX);
92-
reg_expected(hdr, "chr1:50", 0, "", 0, 49, INT_MAX);
90+
reg_expected(hdr, "chr1", 0, "", 0, 0, INT64_MAX);
91+
reg_expected(hdr, "chr1:50", 0, "", 0, 49, INT64_MAX);
9392
reg_expected(hdr, "chr1:50", HTS_PARSE_ONE_COORD, "", 0, 49, 50);
9493
reg_expected(hdr, "chr1:50-100", 0, "", 0, 49, 100);
95-
reg_expected(hdr, "chr1:50-", 0, "", 0, 49, INT_MAX);
94+
reg_expected(hdr, "chr1:50-", 0, "", 0, 49, INT64_MAX);
9695
reg_expected(hdr, "chr1:-50", 0, "", 0, 0, 50);
9796

9897
// Check quoting
9998
fprintf(stderr, "Expected error: ");
10099
reg_expected(hdr, "chr1:100-200", 0, NULL, 0, 0, 0); // ambiguous
101100
reg_expected(hdr, "{chr1}:100-200", 0, "", 0, 99, 200);
102-
reg_expected(hdr, "{chr1:100-200}", 0, "", 2, 0, INT_MAX);
101+
reg_expected(hdr, "{chr1:100-200}", 0, "", 2, 0, INT64_MAX);
103102
reg_expected(hdr, "{chr1:100-200}:100-200", 0, "", 2, 99, 200);
104103
reg_expected(hdr, "{chr2:100-200}:100-200", 0, "", 3, 99, 200);
105104
reg_expected(hdr, "chr2:100-200:100-200", 0, "", 3, 99, 200);
106-
reg_expected(hdr, "chr2:100-200", 0, "", 3, 0, INT_MAX);
105+
reg_expected(hdr, "chr2:100-200", 0, "", 3, 0, INT64_MAX);
107106

108107
// Check numerics
109-
reg_expected(hdr, "chr3", 0, "", 4, 0, INT_MAX);
110-
reg_expected(hdr, "chr3:", 0, "", 4, 0, INT_MAX);
108+
reg_expected(hdr, "chr3", 0, "", 4, 0, INT64_MAX);
109+
reg_expected(hdr, "chr3:", 0, "", 4, 0, INT64_MAX);
111110
reg_expected(hdr, "chr3:1000-1500", 0, "", 4, 999, 1500);
112111
reg_expected(hdr, "chr3:1,000-1,500", 0, "", 4, 999, 1500);
113112
reg_expected(hdr, "chr3:1k-1.5K", 0, "", 4, 999, 1500);
114113
reg_expected(hdr, "chr3:1e3-1.5e3", 0, "", 4, 999, 1500);
115114
reg_expected(hdr, "chr3:1e3-15e2", 0, "", 4, 999, 1500);
116115

117116
// Check list mode
118-
reg_expected(hdr, "chr1,chr3", HTS_PARSE_LIST, "chr3", 0, 0, INT_MAX);
117+
reg_expected(hdr, "chr1,chr3", HTS_PARSE_LIST, "chr3", 0, 0, INT64_MAX);
119118
fprintf(stderr, "Expected error: ");
120119
reg_expected(hdr, "chr1:100-200,chr3", HTS_PARSE_LIST, NULL, 0, 0, 0); // ambiguous
121-
reg_expected(hdr, "{chr1,chr3}", HTS_PARSE_LIST, "", 5, 0, INT_MAX);
122-
reg_expected(hdr, "{chr1,chr3},chr1", HTS_PARSE_LIST, "chr1", 5, 0, INT_MAX);
120+
reg_expected(hdr, "{chr1,chr3}", HTS_PARSE_LIST, "", 5, 0, INT64_MAX);
121+
reg_expected(hdr, "{chr1,chr3},chr1", HTS_PARSE_LIST, "chr1", 5, 0, INT64_MAX);
123122
// incorrect usage; first reg is valid (but not what user expects).
124123
reg_expected(hdr, "chr3:1,000-1,500", HTS_PARSE_LIST | HTS_PARSE_ONE_COORD, "000-1,500", 4, 0, 1);
125124

0 commit comments

Comments
 (0)