Description: <short summary of the patch>
 TODO: Put a short summary on the line above and replace this paragraph
 with a longer explanation of this change. Complete the meta-information
 with other relevant fields (see below for details). To make it easier, the
 information below has been extracted from the changelog. Adjust it or drop
 it.
 .
 htslib (1.2.1-1) UNRELEASED; urgency=medium
 .
   0662716 Merge tag '1.2.1' into debian/unstable
Author: Charles Plessy <plessy@debian.org>

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Debian: https://bugs.debian.org/<bugnumber>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- /dev/null
+++ htslib-1.2.1/.travis.yml
@@ -0,0 +1,8 @@
+# Control file for continuous integration testing at http://travis-ci.org/
+
+language: c
+compiler:
+  - clang
+  - gcc
+
+script: make -e && make test
--- /dev/null
+++ htslib-1.2.1/README.md
@@ -0,0 +1,33 @@
+HTSlib is an implementation of a unified C library for accessing common file
+formats, such as [SAM, CRAM and VCF][1], used for high-throughput sequencing
+data, and is the core library used by [samtools][2] and [bcftools][3].
+HTSlib only depends on [zlib][4].
+It is known to be compatible with gcc, g++ and clang.
+
+HTSlib implements a generalized BAM index, with file extension `.csi`
+(coordinate-sorted index). The HTSlib file reader first looks for the new index
+and then for the old if the new index is absent.
+
+This project also includes the popular tabix indexer, which indexes both `.tbi`
+and `.csi` formats, and the bgzip compression utility.
+
+[1]: http://samtools.github.io/hts-specs/
+[2]: http://github.com/samtools/samtools
+[3]: http://samtools.github.io/bcftools/
+[4]: http://zlib.net/
+
+### Building HTSlib
+
+See [INSTALL](INSTALL) for complete details.
+[Release tarballs][download] contain generated files that have not been
+committed to this repository, so building the code from a Git repository
+requires an extra step:
+
+```sh
+autoconf       # Generate the configure script, if needed
+./configure    # Optional, needed for choosing optional functionality
+make
+make install
+```
+
+[download]: http://www.htslib.org/download/
--- htslib-1.2.1.orig/sam.c
+++ htslib-1.2.1/sam.c
@@ -947,6 +947,12 @@ err_recover:
     }
 }
 
+#define READUNALIGNED(ptr,type) ({ \
+    type tmp;\
+    memcpy(&tmp,ptr,sizeof(type));\
+    tmp;\
+})
+
 int sam_format1(const bam_hdr_t *h, const bam1_t *b, kstring_t *str)
 {
     int i;
@@ -1007,36 +1013,36 @@ int sam_format1(const bam_hdr_t *h, cons
         } else if (type == 'S') {
             if (s+2 <= b->data + b->l_data) {
                 kputsn("i:", 2, str);
-                kputw(*(uint16_t*)s, str);
+                kputw(READUNALIGNED(s,uint16_t), str);
                 s += 2;
             } else return -1;
         } else if (type == 's') {
             if (s+2 <= b->data + b->l_data) {
                 kputsn("i:", 2, str);
-                kputw(*(int16_t*)s, str);
+                kputw(READUNALIGNED(s,int16_t), str);
                 s += 2;
             } else return -1;
         } else if (type == 'I') {
             if (s+4 <= b->data + b->l_data) {
                 kputsn("i:", 2, str);
-                kputuw(*(uint32_t*)s, str);
+                kputuw(READUNALIGNED(s,uint32_t), str);
                 s += 4;
             } else return -1;
         } else if (type == 'i') {
             if (s+4 <= b->data + b->l_data) {
                 kputsn("i:", 2, str);
-                kputw(*(int32_t*)s, str);
+                kputw(READUNALIGNED(s,int32_t), str);
                 s += 4;
             } else return -1;
         } else if (type == 'f') {
             if (s+4 <= b->data + b->l_data) {
-                ksprintf(str, "f:%g", *(float*)s);
+                ksprintf(str, "f:%g", READUNALIGNED(s,float));
                 s += 4;
             } else return -1;
 
         } else if (type == 'd') {
             if (s+8 <= b->data + b->l_data) {
-                ksprintf(str, "d:%g", *(double*)s);
+                ksprintf(str, "d:%g", READUNALIGNED(s,double));
                 s += 8;
             } else return -1;
         } else if (type == 'Z' || type == 'H') {
@@ -1057,11 +1063,11 @@ int sam_format1(const bam_hdr_t *h, cons
                 kputc(',', str);
                 if ('c' == sub_type)      { kputw(*(int8_t*)s, str); ++s; }
                 else if ('C' == sub_type) { kputw(*(uint8_t*)s, str); ++s; }
-                else if ('s' == sub_type) { kputw(*(int16_t*)s, str); s += 2; }
-                else if ('S' == sub_type) { kputw(*(uint16_t*)s, str); s += 2; }
-                else if ('i' == sub_type) { kputw(*(int32_t*)s, str); s += 4; }
-                else if ('I' == sub_type) { kputuw(*(uint32_t*)s, str); s += 4; }
-                else if ('f' == sub_type) { ksprintf(str, "%g", *(float*)s); s += 4; }
+                else if ('s' == sub_type) { kputw(READUNALIGNED(s,int16_t), str); s += 2; }
+                else if ('S' == sub_type) { kputw(READUNALIGNED(s,uint16_t), str); s += 2; }
+                else if ('i' == sub_type) { kputw(READUNALIGNED(s,int32_t), str); s += 4; }
+                else if ('I' == sub_type) { kputuw(READUNALIGNED(s,uint32_t), str); s += 4; }
+                else if ('f' == sub_type) { ksprintf(str, "%g", READUNALIGNED(s,float)); s += 4; }
             }
         }
     }
@@ -1167,9 +1173,9 @@ int32_t bam_aux2i(const uint8_t *s)
     type = *s++;
     if (type == 'c') return (int32_t)*(int8_t*)s;
     else if (type == 'C') return (int32_t)*(uint8_t*)s;
-    else if (type == 's') return (int32_t)*(int16_t*)s;
-    else if (type == 'S') return (int32_t)*(uint16_t*)s;
-    else if (type == 'i' || type == 'I') return *(int32_t*)s;
+    else if (type == 's') return (int32_t)READUNALIGNED(s,int16_t);
+    else if (type == 'S') return (int32_t)READUNALIGNED(s,uint16_t);
+    else if (type == 'i' || type == 'I') return READUNALIGNED(s,int32_t);
     else return 0;
 }
 
@@ -1177,8 +1183,8 @@ double bam_aux2f(const uint8_t *s)
 {
     int type;
     type = *s++;
-    if (type == 'd') return *(double*)s;
-    else if (type == 'f') return *(float*)s;
+    if (type == 'd') return READUNALIGNED(s,double);
+    else if (type == 'f') return READUNALIGNED(s,float);
     else return 0.0;
 }
 
