@@ -2487,9 +2487,11 @@ int bcf_enc_vint(kstring_t *s, int n, int32_t *a, int wsize)
2487
2487
{
2488
2488
int32_t max = INT32_MIN , min = INT32_MAX ;
2489
2489
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 {
2493
2495
if (wsize <= 0 ) wsize = n ;
2494
2496
2495
2497
// Equivalent to:
@@ -2528,9 +2530,9 @@ int bcf_enc_vint(kstring_t *s, int n, int32_t *a, int wsize)
2528
2530
}
2529
2531
2530
2532
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 ;
2534
2536
uint8_t * p = (uint8_t * ) s -> s + s -> l ;
2535
2537
for (i = 0 ; i < n ; ++ i , p ++ ) {
2536
2538
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)
2540
2542
s -> l += n ;
2541
2543
} else if (max <= BCF_MAX_BT_INT16 && min >= BCF_MIN_BT_INT16 ) {
2542
2544
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 ;
2545
2548
p = (uint8_t * ) s -> s + s -> l ;
2546
2549
for (i = 0 ; i < n ; ++ i )
2547
2550
{
@@ -2555,8 +2558,9 @@ int bcf_enc_vint(kstring_t *s, int n, int32_t *a, int wsize)
2555
2558
s -> l += n * sizeof (int16_t );
2556
2559
} else {
2557
2560
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 ;
2560
2564
p = (uint8_t * ) s -> s + s -> l ;
2561
2565
for (i = 0 ; i < n ; ++ i ) {
2562
2566
i32_to_le (a [i ], p );
@@ -2566,7 +2570,7 @@ int bcf_enc_vint(kstring_t *s, int n, int32_t *a, int wsize)
2566
2570
}
2567
2571
}
2568
2572
2569
- return 0 ; // FIXME: check for errs in this function
2573
+ return 0 ;
2570
2574
}
2571
2575
2572
2576
#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,
2932
2936
return 0 ;
2933
2937
}
2934
2938
2935
- // fill the sample fields; at beginning of the loop
2939
+ // Fill the sample fields
2936
2940
static int vcf_parse_format_fill5 (kstring_t * s , const bcf_hdr_t * h , bcf1_t * v ,
2937
2941
const char * p , const char * q , fmt_aux_t * fmt ) {
2938
2942
static int extreme_val_warned = 0 ;
2939
2943
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
2941
2945
const char * t = q + 1 ;
2942
2946
int m = 0 ; // m: sample id
2943
2947
const int nsamples = bcf_hdr_nsamples (h );
0 commit comments