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.
 .
 bedtools (2.19.1-1) unstable; urgency=medium
 .
   479e63b Merge tag 'v2.19.1' into debian/unstable
 .
   [ Charles Plessy ]
   93a7cf1 Create autopkgtest testsuite and a new package bedtools-test.
   46183f8 debian/copyright: update path, correct license short name.
   4fd441a debian/rules: removed obsolete exception of compression.
 .
   [ James McCoy ]
   b4fa8e1 Move debian/upstream to debian/upstream/metadata
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: http://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>

--- bedtools-2.19.1.orig/src/slopBed/slopBed.cpp
+++ bedtools-2.19.1/src/slopBed/slopBed.cpp
@@ -50,12 +50,12 @@ void BedSlop::SlopBed() {
     while (_bed->GetNextBed(bedEntry)) {    
         if (_bed->_status == BED_VALID) {
             if (_fractional == false) {
-                AddSlop(bedEntry, (int) _leftSlop, (int) _rightSlop);
+                AddSlop(bedEntry);
             }
             else {
-                int leftSlop  = (int) (_leftSlop  * bedEntry.size());
-                int rightSlop = (int) (_rightSlop * bedEntry.size());
-                AddSlop(bedEntry, leftSlop, rightSlop);
+                _leftSlop  = _leftSlop  * (float)bedEntry.size();
+                _rightSlop = _rightSlop * (float)bedEntry.size();
+                AddSlop(bedEntry);
             }
             _bed->reportBedNewLine(bedEntry);
         }
@@ -64,29 +64,29 @@ void BedSlop::SlopBed() {
 }
 
 
-void BedSlop::AddSlop(BED &bed, int leftSlop, int rightSlop) {
+void BedSlop::AddSlop(BED &bed) {
 
     // special handling if the BED entry is on the negative
     // strand and the user cares about strandedness.
-    CHRPOS chromSize = _genome->getChromSize(bed.chrom);
+    float chromSize = (float)_genome->getChromSize(bed.chrom);
 
     if ( (_forceStrand) && (bed.strand == "-") ) {
         // inspect the start
-        if ( (static_cast<int>(bed.start) - rightSlop) > 0 ) bed.start -= rightSlop;
-        else bed.start = 0;
+    	float newStart = (float)bed.start - _rightSlop;
+    	bed.start = (newStart > 0 ) ? (CHRPOS)newStart : 0;
 
-        // inspect the start
-        if ( (static_cast<int>(bed.end) + leftSlop) <= static_cast<int>(chromSize)) bed.end += leftSlop;
-        else bed.end = chromSize;
+        // inspect the end
+    	float newEnd = (float)bed.end + _leftSlop;
+    	bed.end = (newEnd < chromSize ) ? (CHRPOS)newEnd : (CHRPOS)chromSize;
     }
     else {
         // inspect the start
-        if ( (static_cast<int>(bed.start) - leftSlop) > 0) bed.start -= leftSlop;
-        else bed.start = 0;
+    	float newStart = (float)bed.start - _leftSlop;
+    	bed.start = (newStart > 0 ) ? (CHRPOS)newStart : 0;
 
         // inspect the end
-        if ( (static_cast<int>(bed.end) + rightSlop) <= static_cast<int>(chromSize)) bed.end += rightSlop;
-        else bed.end = chromSize;
+    	float newEnd = (float)bed.end + _rightSlop;
+    	bed.end = (newEnd < chromSize ) ? (CHRPOS)newEnd : (CHRPOS)chromSize;
     }
 }
 
--- bedtools-2.19.1.orig/src/slopBed/slopBed.h
+++ bedtools-2.19.1/src/slopBed/slopBed.h
@@ -57,5 +57,5 @@ private:
     void SlopBed();
 
     // method to add requested "slop" to a single BED entry
-    void AddSlop(BED &bed, int leftSlop, int rightSlop);
+    void AddSlop(BED &bed);
 };
--- bedtools-2.19.1.orig/src/utils/fileType/fileType.cpp
+++ bedtools-2.19.1/src/utils/fileType/fileType.cpp
@@ -48,24 +48,31 @@ bool isGzipFile(istream *file) {
        without triggering the "fail" bit.  This was necessary to support
        FIFOs, per version 2.13.0
     */
-    struct  {
-        unsigned char id1;
+//    struct  {
+//        unsigned char id1;
 //      unsigned char id2;
 //      unsigned char cm;
-    } gzip_header;
+//    } gzip_header;
 
-    if (!file->read((char*)&gzip_header, sizeof(gzip_header))) {
-        return false;
-    }
-
-    if ( gzip_header.id1 == 0x1f )
+//   if (!file->read((char*)&gzip_header, sizeof(gzip_header))) {
+//       return false;
+//   }
+//  if ( gzip_header.id1 == 0x1f )
 //       &&
 //       gzip_header.id2 == 0x8b
 //       &&
 //       gzip_header.cm == 8 )
+
+/*
+        26-Dec-2012 and again 20-Mar-2014:
+        Just peek at the first byte instead of reading it so that we don't
+        affect the istream's failbit.  This modification was wisely proposed
+        by John Marshall in response to Issue 30:
+        https://github.com/arq5x/bedtools/issues/30
+ */
+    if (file->peek() != 0x1f)
     {
         return true;
     }
-    file->putback(gzip_header.id1);
     return false;
 }
--- bedtools-2.19.1.orig/test/map/test-map.sh
+++ bedtools-2.19.1/test/map/test-map.sh
@@ -694,7 +694,7 @@ echo \
 "
 *****
 ***** ERROR: There are 1 columns given, but there are 2 operations."  > exp
-../../bin/bedtools map -a ivls.bed -b values.bed -o count,sum 2>&1 > /dev/null | head -3 > obs
+$BT map -a ivls.bed -b values.bed -o count,sum 2>&1 > /dev/null | head -3 > obs
 check obs exp
 rm obs exp
 
@@ -708,7 +708,7 @@ echo \
 "
 *****
 ***** ERROR: There are 3 columns given, but there are 2 operations."  > exp
-../../bin/bedtools map -a ivls.bed -b values.bed -c 5,1,2 -o count,sum 2>&1 > /dev/null | head -3 > obs
+$BT map -a ivls.bed -b values.bed -c 5,1,2 -o count,sum 2>&1 > /dev/null | head -3 > obs
 check obs exp
 rm obs exp
 
@@ -721,7 +721,7 @@ echo \
 "
 *****
 ***** ERROR: Column 1 is not a numeric field for database file values.bed."  > exp
-../../bin/bedtools map -a ivls.bed -b values.bed -c 1 -o sum 2>&1 > /dev/null | head -3 > obs
+$BT map -a ivls.bed -b values.bed -c 1 -o sum 2>&1 > /dev/null | head -3 > obs
 check obs exp
 rm obs exp
 
@@ -738,7 +738,7 @@ chr2	0	100	.	.
 chr2	100	200	.	.
 chr3	0	100	6	7
 chr3	100	200	8	23" > exp
-../../bin/bedtools map -a ivls.bed -b values4.bed -c 5,7 -o sum > obs
+$BT map -a ivls.bed -b values4.bed -c 5,7 -o sum > obs
 check obs exp
 rm obs exp
 
@@ -755,7 +755,7 @@ chr2	0	100	.	.	.
 chr2	100	200	.	.	.
 chr3	0	100	10	6	7
 chr3	100	200	120	8	23" > exp
-../../bin/bedtools map -a ivls.bed -b values4.bed -c 2,5,7 -o mean,sum,sum > obs
+$BT map -a ivls.bed -b values4.bed -c 2,5,7 -o mean,sum,sum > obs
 check obs exp
 rm obs exp
 
@@ -771,7 +771,7 @@ chr2	0	100	.
 chr2	100	200	.
 chr3	0	100	76.2222
 chr3	100	200	0.25" > exp
-../../bin/bedtools map -a ivls.bed -b values4.bed -c 7 -o stddev > obs
+$BT map -a ivls.bed -b values4.bed -c 7 -o stddev > obs
 check obs exp
 rm obs exp
 
@@ -786,7 +786,7 @@ chr2	0	100	.
 chr2	100	200	.
 chr3	0	100	114.333
 chr3	100	200	0.5" > exp
-../../bin/bedtools map -a ivls.bed -b values4.bed -c 7 -o sample_stddev > obs
+$BT map -a ivls.bed -b values4.bed -c 7 -o sample_stddev > obs
 check obs exp
 rm obs exp
 
--- bedtools-2.19.1.orig/test/reldist/test-reldist.sh
+++ bedtools-2.19.1/test/reldist/test-reldist.sh
@@ -1,4 +1,5 @@
 BT=${BT-../../bin/bedtools}
+DATA=${DATA-../../data}
 
 check()
 {
@@ -17,8 +18,8 @@ echo "    reldist.t01...\c"
 echo \
 "reldist	count	total	fraction
 0.00	43424	43424	1.000" > exp
-$BT reldist -a ../../data/refseq.chr1.exons.bed.gz \
-            -b ../../data/refseq.chr1.exons.bed.gz > obs
+$BT reldist -a $DATA/refseq.chr1.exons.bed.gz \
+            -b $DATA/refseq.chr1.exons.bed.gz > obs
 check obs exp
 rm obs exp
 
@@ -79,8 +80,8 @@ echo \
 0.47	850	43408	0.020
 0.48	1006	43408	0.023
 0.49	937	43408	0.022" > exp
-$BT reldist -a ../../data/refseq.chr1.exons.bed.gz \
-            -b ../../data/aluY.chr1.bed.gz > obs
+$BT reldist -a $DATA/refseq.chr1.exons.bed.gz \
+            -b $DATA/aluY.chr1.bed.gz > obs
 check obs exp
 rm obs exp
 
@@ -143,7 +144,7 @@ echo \
 0.48	365	43422	0.008
 0.49	336	43422	0.008
 0.50	38	43422	0.001" > exp
-$BT reldist -a ../../data/refseq.chr1.exons.bed.gz \
-            -b ../../data/gerp.chr1.bed.gz > obs
+$BT reldist -a $DATA/refseq.chr1.exons.bed.gz \
+            -b $DATA/gerp.chr1.bed.gz > obs
 check obs exp
-rm obs exp
\ No newline at end of file
+rm obs exp
--- bedtools-2.19.1.orig/test/slop/test-slop.sh
+++ bedtools-2.19.1/test/slop/test-slop.sh
@@ -134,4 +134,16 @@ echo \
 chr1	0	1000	a2	2	-" > exp
 $BT slop -i a.bed -b 2000 -s -g tiny.genome > obs
 check obs exp
-rm obs exp
\ No newline at end of file
+rm obs exp
+
+###########################################################
+# test slop factor being larger than a signed int
+###########################################################
+echo "    slop.t12...\c"
+echo \
+"chr1	0	1000	a1	1	+
+chr1	0	1000	a2	2	-" > exp
+$BT slop -i a.bed -b 3000000000 -s -g tiny.genome > obs
+check obs exp
+rm obs exp
+
