Merge commit 'upstream/0.1.18'
[samtools.git] / bedidx.c
index 722877dcc2aa1d414460c328e6e022a22befecfe..ec75a1067f5905c69ead868ff42d2073189bb690 100644 (file)
--- a/bedidx.c
+++ b/bedidx.c
@@ -4,6 +4,10 @@
 #include <stdio.h>
 #include <zlib.h>
 
+#ifdef _WIN32
+#define drand48() ((double)rand() / RAND_MAX)
+#endif
+
 #include "ksort.h"
 KSORT_INIT_GENERIC(uint64_t)
 
@@ -119,8 +123,10 @@ void *bed_read(const char *fn)
                        if (ks_getuntil(ks, 0, str, &dret) > 0 && isdigit(str->s[0])) {
                                beg = atoi(str->s); // begin
                                if (dret != '\n') {
-                                       if (ks_getuntil(ks, 0, str, &dret) > 0 && isdigit(str->s[0]))
+                                       if (ks_getuntil(ks, 0, str, &dret) > 0 && isdigit(str->s[0])) {
                                                end = atoi(str->s); // end
+                                               if (end < beg) end = -1;
+                                       }
                                }
                        }
                }