Skip to content

Commit ca2f667

Browse files
pd3valeriuo
authored andcommitted
Polish a few minor details
- bug fix in `bcf_dec_typed_int1_safe()`, 64-bit values could not have been read correctly by this function - cosmetic change to declare val1 always as int64_t and explicit cast to int32_t and add explicit LL to a 64-bit constant in case some compilers were fussy (cherry picked from commit ecc69cf)
1 parent a53582f commit ca2f667

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@ RANLIB = ranlib
3030
htslib_default_libs = -lz -lm -lbz2 -llzma -lcurl
3131

3232
CPPFLAGS =
33-
# TODO: make the 64-bit support for VCF optional via configure, for now add -DVCF_ALLOW_INT64=1 to CFLAGS manually
33+
# TODO: make the 64-bit support for VCF optional via configure, for now add -DVCF_ALLOW_INT64
34+
# to CFLAGS manually, here or in config.mk if the latter exists.
3435
# TODO: probably update cram code to make it compile cleanly with -Wc++-compat
3536
# For testing strict C99 support add -std=c99 -D_XOPEN_SOURCE=600
3637
#CFLAGS = -g -Wall -O2 -pedantic -std=c99 -D_XOPEN_SOURCE=600

vcf.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ static bcf_idinfo_t bcf_idinfo_def = { .info = { 15, 15, 15 }, .hrec = { NULL, N
7272
- experimental, use at your risk
7373
*/
7474
#ifdef VCF_ALLOW_INT64
75-
#define BCF_MAX_BT_INT64 (0x7fffffffffffffff) /* INT64_MAX, for internal use only */
76-
#define BCF_MIN_BT_INT64 -9223372036854775800 /* INT64_MIN + 8, for internal use only */
75+
#define BCF_MAX_BT_INT64 (0x7fffffffffffffff) /* INT64_MAX, for internal use only */
76+
#define BCF_MIN_BT_INT64 -9223372036854775800LL /* INT64_MIN + 8, for internal use only */
7777
#endif
7878

7979
#define BCF_IS_64BIT (1<<30)
@@ -1269,9 +1269,11 @@ static int bcf_dec_typed_int1_safe(uint8_t *p, uint8_t *end, uint8_t **q,
12691269
*val = le_to_i32(p);
12701270
#ifdef VCF_ALLOW_INT64
12711271
} else if (t == BCF_BT_INT64) {
1272-
if (end - p < 4) return -1;
1273-
*q = p + 4;
1274-
*val = le_to_i32(p);
1272+
// This case should never happen because there should be no 64-bit BCFs
1273+
// at all, definitely not coming from htslib
1274+
if (end - p < 8) return -1;
1275+
*q = p + 8;
1276+
*val = le_to_i64(p);
12751277
#endif
12761278
} else {
12771279
return -1;
@@ -2726,9 +2728,9 @@ int vcf_parse(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v)
27262728
}
27272729
if ((y>>4&0xf) == BCF_HT_INT) {
27282730
i = 0, t = val;
2731+
int64_t val1;
27292732
#ifdef VCF_ALLOW_INT64
27302733
int is_int64 = 0;
2731-
int64_t val1;
27322734
if ( n_val==1 )
27332735
{
27342736
errno = 0;
@@ -2749,8 +2751,6 @@ int vcf_parse(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v)
27492751
t = te;
27502752
i = 1; // this is just to avoid adding another nested block...
27512753
}
2752-
#else
2753-
int32_t val1;
27542754
#endif
27552755
for (; i < n_val; ++i, ++t)
27562756
{
@@ -2777,10 +2777,10 @@ int vcf_parse(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v)
27772777
bcf_enc_long1(str, val1);
27782778
}
27792779
else
2780-
bcf_enc_int1(str, val1);
2780+
bcf_enc_int1(str, (int32_t)val1);
27812781
#else
27822782
val1 = val_a[0];
2783-
bcf_enc_int1(str, val1);
2783+
bcf_enc_int1(str, (int32_t)val1);
27842784
#endif
27852785
} else {
27862786
bcf_enc_vint(str, n_val, val_a, -1);

0 commit comments

Comments
 (0)