Skip to content

Commit 4acd44e

Browse files
Add tests and fix missing error check
1 parent 2fb90a5 commit 4acd44e

File tree

2 files changed

+23
-18
lines changed

2 files changed

+23
-18
lines changed

lib/tests.c

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -50,34 +50,36 @@ validate_encoder(
5050
/* vcz_variant_encoder_print_state(encoder, stdout); */
5151

5252
for (j = 0; j < num_rows; j++) {
53-
/* We need space for the NULL byte as well */
54-
min_len = (int64_t) strlen(expected[j]) + 1;
5553
/* printf("expected: %s\n", expected[j]); */
5654

55+
/* We need space for the NULL byte as well */
56+
min_len = (int64_t) strlen(expected[j]) + 1;
5757
for (buflen = 0; buflen < min_len; buflen++) {
5858
buf = malloc((size_t) buflen);
5959
CU_ASSERT_FATAL(buf != NULL);
6060
ret = vcz_variant_encoder_encode(encoder, j, buf, (size_t) buflen);
6161
free(buf);
6262
CU_ASSERT_FATAL(ret == VCZ_ERR_BUFFER_OVERFLOW);
6363
}
64+
6465
buflen = min_len;
6566
buf = malloc((size_t) buflen);
6667
CU_ASSERT_FATAL(buf != NULL);
6768
ret = vcz_variant_encoder_encode(encoder, j, buf, (size_t) buflen);
68-
/* printf("ret = %d\n", (int) ret); */
69-
/* printf("GOT:'%s'\n", buf); */
70-
/* printf("EXP:'%s'\n", expected[j]); */
71-
/* printf("GOT:%d\n", (int) strlen(buf)); */
72-
/* printf("EXP:%d\n", (int) strlen(expected[j])); */
73-
/* int64_t c; */
74-
/* for (c = 0; c < ret; c++) { */
75-
/* if (buf[c] != expected[j][c]) { */
76-
/* printf("Mismatch at %d: %c != %c\n", (int) c, buf[c], expected[j][c]);
77-
*/
78-
79-
/* } */
80-
/* } */
69+
/*
70+
printf("ret = %d\n", (int) ret);
71+
printf("GOT:'%s'\n", buf);
72+
printf("EXP:'%s'\n", expected[j]);
73+
printf("GOT:%d\n", (int) strlen(buf));
74+
printf("EXP:%d\n", (int) strlen(expected[j]));
75+
int64_t c;
76+
for (c = 0; c < ret; c++) {
77+
if (buf[c] != expected[j][c]) {
78+
printf("Mismatch at %d: %c != %c\n", (int) c, buf[c], expected[j][c]);
79+
80+
}
81+
}
82+
*/
8183
CU_ASSERT_EQUAL_FATAL(ret, strlen(expected[j]));
8284
CU_ASSERT_NSTRING_EQUAL_FATAL(buf, expected[j], ret);
8385
free(buf);
@@ -370,7 +372,7 @@ test_variant_encoder_minimal(void)
370372
const char alt_data[] = "T";
371373
const float qual_data[] = { 9, 12.1f };
372374
const char filter_id_data[] = "PASS\0FILT1";
373-
const int8_t filter_data[] = { 1, 0, 0, 1 };
375+
const int8_t filter_data[] = { 1, 1, 0, 1 };
374376
const int32_t an_data[] = { -1, 9 };
375377
const char *aa_data = "G.";
376378
const int8_t flag_data[] = { 0, 1 };
@@ -381,7 +383,7 @@ test_variant_encoder_minimal(void)
381383
int64_t ret;
382384
vcz_variant_encoder_t writer;
383385
const char *expected[] = {
384-
"X\t123\tRS1\tA\tT\t9\tPASS\tAA=G\tGT:HQ:GL\t0/0:10,15:1,2\t0|1:7,12:3,4",
386+
"X\t123\tRS1\tA\tT\t9\tPASS;FILT1\tAA=G\tGT:HQ:GL\t0/0:10,15:1,2\t0|1:7,12:3,4",
385387
"YY\t45678\tRS2\tG\t.\t12.1\tFILT1\tAN=9;FLAG\tGT:GL\t1|1:1.1,1.2\t1/0:1.3,1.4",
386388
};
387389

lib/vcf_encoder.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,10 +748,13 @@ vcz_variant_encoder_write_filter(const vcz_variant_encoder_t *self, size_t varia
748748
source_offset = 0;
749749
for (j = 0; j < filter_id.num_columns; j++) {
750750
if (data[j]) {
751+
source_offset = j * filter_id.item_size;
751752
if (!first) {
752753
offset = append_char(buf, ';', offset, buflen);
754+
if (offset < 0) {
755+
goto out;
756+
}
753757
}
754-
source_offset = j * filter_id.item_size;
755758
for (k = 0; k < filter_id.item_size; k++) {
756759
if (filter_id_data[source_offset] == VCZ_STRING_FILL) {
757760
break;

0 commit comments

Comments
 (0)