Skip to content

Commit

Permalink
Polish a few minor details
Browse files Browse the repository at this point in the history
- 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)
  • Loading branch information
pd3 authored and valeriuo committed Dec 16, 2019
1 parent a53582f commit ca2f667
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ RANLIB = ranlib
htslib_default_libs = -lz -lm -lbz2 -llzma -lcurl

CPPFLAGS =
# TODO: make the 64-bit support for VCF optional via configure, for now add -DVCF_ALLOW_INT64=1 to CFLAGS manually
# TODO: make the 64-bit support for VCF optional via configure, for now add -DVCF_ALLOW_INT64
# to CFLAGS manually, here or in config.mk if the latter exists.
# TODO: probably update cram code to make it compile cleanly with -Wc++-compat
# For testing strict C99 support add -std=c99 -D_XOPEN_SOURCE=600
#CFLAGS = -g -Wall -O2 -pedantic -std=c99 -D_XOPEN_SOURCE=600
Expand Down
20 changes: 10 additions & 10 deletions vcf.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ static bcf_idinfo_t bcf_idinfo_def = { .info = { 15, 15, 15 }, .hrec = { NULL, N
- experimental, use at your risk
*/
#ifdef VCF_ALLOW_INT64
#define BCF_MAX_BT_INT64 (0x7fffffffffffffff) /* INT64_MAX, for internal use only */
#define BCF_MIN_BT_INT64 -9223372036854775800 /* INT64_MIN + 8, for internal use only */
#define BCF_MAX_BT_INT64 (0x7fffffffffffffff) /* INT64_MAX, for internal use only */
#define BCF_MIN_BT_INT64 -9223372036854775800LL /* INT64_MIN + 8, for internal use only */
#endif

#define BCF_IS_64BIT (1<<30)
Expand Down Expand Up @@ -1269,9 +1269,11 @@ static int bcf_dec_typed_int1_safe(uint8_t *p, uint8_t *end, uint8_t **q,
*val = le_to_i32(p);
#ifdef VCF_ALLOW_INT64
} else if (t == BCF_BT_INT64) {
if (end - p < 4) return -1;
*q = p + 4;
*val = le_to_i32(p);
// This case should never happen because there should be no 64-bit BCFs
// at all, definitely not coming from htslib
if (end - p < 8) return -1;
*q = p + 8;
*val = le_to_i64(p);
#endif
} else {
return -1;
Expand Down Expand Up @@ -2726,9 +2728,9 @@ int vcf_parse(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v)
}
if ((y>>4&0xf) == BCF_HT_INT) {
i = 0, t = val;
int64_t val1;
#ifdef VCF_ALLOW_INT64
int is_int64 = 0;
int64_t val1;
if ( n_val==1 )
{
errno = 0;
Expand All @@ -2749,8 +2751,6 @@ int vcf_parse(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v)
t = te;
i = 1; // this is just to avoid adding another nested block...
}
#else
int32_t val1;
#endif
for (; i < n_val; ++i, ++t)
{
Expand All @@ -2777,10 +2777,10 @@ int vcf_parse(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v)
bcf_enc_long1(str, val1);
}
else
bcf_enc_int1(str, val1);
bcf_enc_int1(str, (int32_t)val1);
#else
val1 = val_a[0];
bcf_enc_int1(str, val1);
bcf_enc_int1(str, (int32_t)val1);
#endif
} else {
bcf_enc_vint(str, n_val, val_a, -1);
Expand Down

0 comments on commit ca2f667

Please sign in to comment.