Hi, Dominique

System endianness issue refers to a bug in function swap_endian_data 
(bam.c:160).

Function swap_endian_data() is used on big-endian architectures when data is 
read from input BAM files and/or written to output BAM files, for converting 
multibyte integer values from little endian to big endian byte order and vice 
versa (depending on the operation).

Additional argument to the function is_host specifies whether the input data is 
in host byte order or not (reading or writing), since swapping of BAM auxiliary 
array length values has to be done at different times for reading and writing.

-static void swap_endian_data(const bam1_core_t *c, int data_len, uint8_t *data)
+static void swap_endian_data(const bam1_core_t *c, int data_len, uint8_t 
*data, int is_host)

+            if(!is_host) bam_swap_endian_4p(s+1);

-            bam_swap_endian_4p(s+1);
+            if(is_host) bam_swap_endian_4p(s+1);
+            s += n * Bsize + 4;

The last line in this change updates pointer 's' so that it points to the next 
uxiliary data tag-value pair (there are 'n' elements, each element of the array 
is Bsize bytes long; additional 4 bytes are for the 4-byte integer  where 
length of array is stored).

The following  fixes 'for' loop limits (there are 'n' elements and each element 
is Bsize bytes long):

-                for (i = 0; i < n; i += 2)
+                for (i = 0; i < n*Bsize; i += 2)

-                for (i = 0; i < n; i += 4)
+                for (i = 0; i < n*Bsize; i += 4)


Changes in fix_alignment.patch are to avoid unaligned memory access for 
architectures that don't allow it.

I am currently adapting changes to the latest version of samtools. When I'm 
done I will contact upstream.

Best Regards
Aleksandar Zlicic


Reply via email to