Package: staden-io-lib / 1.14.11-6

d4591b5.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
From: James Bonfield <jkb@sanger.ac.uk>
Date: Wed, 5 Dec 2018 14:51:09 +0000
Origin: https://github.com/jkbonfield/io_lib/commit/d4591b5.patch
Bug-Debian: https://bugs.debian.org/915450
Subject: [PATCH] Big endian fix for BAM reading.

Fixes Debian Bug#915450
---
 io_lib/bam.c | 52 +++++++++++++++++++++++++++-------------------------
 1 file changed, 27 insertions(+), 25 deletions(-)

diff --git a/io_lib/bam.c b/io_lib/bam.c
index 55d0919..b259b50 100644
--- a/io_lib/bam.c
+++ b/io_lib/bam.c
@@ -716,7 +716,7 @@ void *bgzf_decode_thread(void *arg) {
 	uint32_t crc1=libdeflate_crc32(0L, (unsigned char *)j->uncomp, j->uncomp_sz);
 	uint32_t crc2;
 	memcpy(&crc2, j->comp + j->comp_sz, 4);
-	crc2 = le_int2(crc2);
+	crc2 = le_int4(crc2);
 	if (crc1 != crc2) {
 	    fprintf(stderr, "Invalid CRC in Deflate stream: %08x vs %08x\n",
 		    crc1, crc2);
@@ -754,7 +754,7 @@ void *bgzf_decode_thread(void *arg) {
 	uint32_t crc1=iolib_crc32(0L, (unsigned char *)j->uncomp, s.total_out);
 	uint32_t crc2;
 	memcpy(&crc2, j->comp + j->comp_sz, 4);
-	crc2 = le_int2(crc2);
+	crc2 = le_int4(crc2);
 	if (crc1 != crc2) {
 	    fprintf(stderr, "Invalid CRC in Deflate stream: %08x vs %08x\n",
 		    crc1, crc2);
@@ -1055,7 +1055,7 @@ static int bam_uncompress_input(bam_file_t *b) {
 					    b->uncomp_sz);
 		uint32_t crc2;
 		memcpy(&crc2, b->comp_p-8, 4);
-		crc2 = le_int2(crc2);
+		crc2 = le_int4(crc2);
 		if (crc1 != crc2) {
 		    fprintf(stderr, "Invalid CRC in Deflate stream: "
 			    "%08x vs %08x\n", crc1, crc2);
@@ -1656,7 +1656,8 @@ static int sam_next_seq(bam_file_t *b, bam_seq_t **bsp) {
 int bam_get_seq(bam_file_t *b, bam_seq_t **bsp) {
     int32_t blk_size, blk_ret;
     bam_seq_t *bs;
-    uint32_t i32;
+    uint32_t u32;
+    int32_t i32;
 
     b->line++;
 
@@ -1701,22 +1702,22 @@ int bam_get_seq(bam_file_t *b, bam_seq_t **bsp) {
 
     bs->blk_size  = blk_size;
     bs->ref       = le_int4(bs->ref);
-    bs->pos       = le_int4(bs->pos_32);
+    i32 = le_int4(bs->pos_32); bs->pos = i32;
 
     // order of bit-fields in struct is platform specific, so manually decode
-    i32           = le_int4(bs->bin_packed);
-    bs->bin      = i32 >> 16;
-    bs->map_qual = (i32 >> 8) & 0xff;
-    bs->name_len = i32 & 0xff;
+    u32           = le_int4(bs->bin_packed);
+    bs->bin      = u32 >> 16;
+    bs->map_qual = (u32 >> 8) & 0xff;
+    bs->name_len = u32 & 0xff;
 
-    i32           = le_int4(bs->flag_packed);
-    bs->flag      = i32 >> 16;
-    bs->cigar_len = i32 & 0xffff;
+    u32           = le_int4(bs->flag_packed);
+    bs->flag      = u32 >> 16;
+    bs->cigar_len = u32 & 0xffff;
 
     bs->len       = le_int4(bs->len);
     bs->mate_ref  = le_int4(bs->mate_ref);
-    bs->mate_pos  = le_int4(bs->mate_pos_32);
-    bs->ins_size  = le_int4(bs->ins_size_32);
+    i32 = le_int4(bs->mate_pos_32); bs->mate_pos = i32;
+    i32 = le_int4(bs->ins_size_32); bs->ins_size = i32;
 
     if (10 == be_int4(10)) {
 	int i, cigar_len = bam_cigar_len(bs);
@@ -1734,7 +1735,8 @@ int bam_get_seq(bam_file_t *b, bam_seq_t **bsp) {
 int bam_get_seq(bam_file_t *b, bam_seq_t **bsp) {
     int32_t blk_size, blk_ret;
     bam_seq_t *bs;
-    uint32_t i32;
+    uint32_t u32;
+    int32_t i32;
 
     b->line++;
 
@@ -1769,22 +1771,22 @@ int bam_get_seq(bam_file_t *b, bam_seq_t **bsp) {
 
     bs->blk_size  = blk_size;
     bs->ref       = le_int4(bs->ref);
-    bs->pos       = le_int4(bs->pos_32);
+    i32 = le_int4(bs->pos_32); bs->pos = i32;
 
     // order of bit-fields in struct is platform specific, so manually decode
-    i32           = le_int4(bs->bin_packed);
-    bs->bin      = i32 >> 16;
-    bs->map_qual = (i32 >> 8) & 0xff;
-    bs->name_len = i32 & 0xff;
+    u32           = le_int4(bs->bin_packed);
+    bs->bin      = u32 >> 16;
+    bs->map_qual = (u32 >> 8) & 0xff;
+    bs->name_len = u32 & 0xff;
 
-    i32           = le_int4(bs->flag_packed);
-    bs->flag      = i32 >> 16;
-    bs->cigar_len = i32 & 0xffff;
+    u32           = le_int4(bs->flag_packed);
+    bs->flag      = u32 >> 16;
+    bs->cigar_len = u32 & 0xffff;
 
     bs->len       = le_int4(bs->len);
     bs->mate_ref  = le_int4(bs->mate_ref);
-    bs->mate_pos  = le_int4(bs->mate_pos_32);
-    bs->ins_size  = le_int4(bs->ins_size_32);
+    i32 = le_int4(bs->mate_pos_32); bs->mate_pos = i32;
+    i32 = le_int4(bs->ins_size_32); bs->ins_size = i32;
 
     /* Name */
     if (bam_read(b, &bs->data, bam_name_len(bs)) != bam_name_len(bs))