Skip to content

Commit e1bbc3f

Browse files
committed
More review commits
1 parent 59d14e9 commit e1bbc3f

File tree

2 files changed

+17
-23
lines changed

2 files changed

+17
-23
lines changed

htslib/vcf.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,16 +1562,6 @@ static inline int bcf_enc_inttype(long x)
15621562
return BCF_BT_INT32;
15631563
}
15641564

1565-
// INTERNAL - not to be assumed to be a part of public API
1566-
// As per bcf_enc_size but kstring is already guaranteed to be big enough
1567-
// and with size == 1.
1568-
static inline void bcf_enc_size1_(kstring_t *s, int type)
1569-
{
1570-
uint8_t *p = (uint8_t *)s->s + s->l;
1571-
*p++ = (1<<4) | type;
1572-
s->l++;
1573-
}
1574-
15751565
static inline int bcf_enc_int1(kstring_t *s, int32_t x)
15761566
{
15771567
if (ks_resize(s, s->l + 5) < 0)

vcf.c

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2487,9 +2487,11 @@ int bcf_enc_vint(kstring_t *s, int n, int32_t *a, int wsize)
24872487
{
24882488
int32_t max = INT32_MIN, min = INT32_MAX;
24892489
int i;
2490-
if (n <= 0) bcf_enc_size(s, 0, BCF_BT_NULL);
2491-
else if (n == 1) bcf_enc_int1(s, a[0]);
2492-
else {
2490+
if (n <= 0) {
2491+
return bcf_enc_size(s, 0, BCF_BT_NULL);
2492+
} else if (n == 1) {
2493+
return bcf_enc_int1(s, a[0]);
2494+
} else {
24932495
if (wsize <= 0) wsize = n;
24942496

24952497
// Equivalent to:
@@ -2528,9 +2530,9 @@ int bcf_enc_vint(kstring_t *s, int n, int32_t *a, int wsize)
25282530
}
25292531

25302532
if (max <= BCF_MAX_BT_INT8 && min >= BCF_MIN_BT_INT8) {
2531-
bcf_enc_size(s, wsize, BCF_BT_INT8);
2532-
2533-
ks_resize(s, s->l + n);
2533+
if (bcf_enc_size(s, wsize, BCF_BT_INT8) < 0 ||
2534+
ks_resize(s, s->l + n) < 0)
2535+
return -1;
25342536
uint8_t *p = (uint8_t *) s->s + s->l;
25352537
for (i = 0; i < n; ++i, p++) {
25362538
if ( a[i]==bcf_int32_vector_end ) *p = bcf_int8_vector_end;
@@ -2540,8 +2542,9 @@ int bcf_enc_vint(kstring_t *s, int n, int32_t *a, int wsize)
25402542
s->l += n;
25412543
} else if (max <= BCF_MAX_BT_INT16 && min >= BCF_MIN_BT_INT16) {
25422544
uint8_t *p;
2543-
bcf_enc_size(s, wsize, BCF_BT_INT16);
2544-
ks_resize(s, s->l + n * sizeof(int16_t));
2545+
if (bcf_enc_size(s, wsize, BCF_BT_INT16) < 0 ||
2546+
ks_resize(s, s->l + n * sizeof(int16_t)) < 0)
2547+
return -1;
25452548
p = (uint8_t *) s->s + s->l;
25462549
for (i = 0; i < n; ++i)
25472550
{
@@ -2555,8 +2558,9 @@ int bcf_enc_vint(kstring_t *s, int n, int32_t *a, int wsize)
25552558
s->l += n * sizeof(int16_t);
25562559
} else {
25572560
uint8_t *p;
2558-
bcf_enc_size(s, wsize, BCF_BT_INT32);
2559-
ks_resize(s, s->l + n * sizeof(int32_t));
2561+
if (bcf_enc_size(s, wsize, BCF_BT_INT32) < 0 ||
2562+
ks_resize(s, s->l + n * sizeof(int32_t)) < 0)
2563+
return -1;
25602564
p = (uint8_t *) s->s + s->l;
25612565
for (i = 0; i < n; ++i) {
25622566
i32_to_le(a[i], p);
@@ -2566,7 +2570,7 @@ int bcf_enc_vint(kstring_t *s, int n, int32_t *a, int wsize)
25662570
}
25672571
}
25682572

2569-
return 0; // FIXME: check for errs in this function
2573+
return 0;
25702574
}
25712575

25722576
#ifdef VCF_ALLOW_INT64
@@ -2932,12 +2936,12 @@ static int vcf_parse_format_alloc4(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v,
29322936
return 0;
29332937
}
29342938

2935-
// fill the sample fields; at beginning of the loop
2939+
// Fill the sample fields
29362940
static int vcf_parse_format_fill5(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v,
29372941
const char *p, const char *q, fmt_aux_t *fmt) {
29382942
static int extreme_val_warned = 0;
29392943
int n_sample_ori = -1;
2940-
// t points to the first char of a format
2944+
// At beginning of the loop t points to the first char of a format
29412945
const char *t = q + 1;
29422946
int m = 0; // m: sample id
29432947
const int nsamples = bcf_hdr_nsamples(h);

0 commit comments

Comments
 (0)