@@ -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
@@ -2832,7 +2836,7 @@ static int vcf_parse_format_max3(kstring_t *s, const bcf_hdr_t *h, bcf1_t *v,
28322836 char * r_start = r ;
28332837 for (;;) {
28342838 // Quickly skip ahead to an appropriate meta-character
2835- while (!meta [(unsigned )* r ]) r ++ ;
2839+ while (!meta [(unsigned char )* r ]) r ++ ;
28362840
28372841 switch (* r ) {
28382842 case ',' :
@@ -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
29362940static 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