Browse code

fix a randomly occuring crash

git-svn-id: file:///home/git/hedgehog.fhcrc.org/bioconductor/trunk/madman/Rpacks/seqbias@54119 bc3139a8-67e5-0310-9ffc-ced21a209358

Daniel Jones authored on 28/03/2011 21:08:28
Showing 4 changed files

... ...
@@ -1,5 +1,5 @@
1 1
 Package: seqbias
2
-Version: 0.99.8
2
+Version: 0.99.9
3 3
 Date: 25-12-2010
4 4
 Title: Estimation of per-position bias in high-throughput sequencing data
5 5
 Description: This package implements a model of per-position sequencing bias in
... ...
@@ -16,5 +16,5 @@ SEQBIAS_OBJ = sequencing_bias.o kmers.o miscmath.o common.o \
16 16
 
17 17
 GNULIB_OBJ = asprintf.o printf-args.o printf-parse.o vasnprintf.o vasprintf.o
18 18
 
19
-PKG_CFLAGS  += -Wall
19
+PKG_CFLAGS  += -Wall -D_GNU_SOURCE
20 20
 
... ...
@@ -11,8 +11,15 @@ extern "C" {
11 11
 #ifndef NEED_ASPRINTF
12 12
 #include <stdio.h>
13 13
 #else
14
-int asprintf (char **resultp, const char *format, ...);
14
+
15
+#include <stdarg.h>
16
+
15 17
 /* defined in gnulib/asprintf.c */
18
+int asprintf (char **resultp, const char *format, ...);
19
+
20
+/* defined in gnulib/vasprintf.c */
21
+int vasprintf(char **strp, const char *fmt, va_list ap);
22
+
16 23
 #endif
17 24
 
18 25
 
... ...
@@ -368,12 +368,12 @@ void sequencing_bias::build( const char* ref_fn,
368 368
 
369 369
         /* add a foreground sequence */
370 370
         if( S[i].strand ) {
371
-            if( S[i].pos < R ) continue;
371
+            if( S[i].pos < R || S[i].pos >= seqlen - L ) continue;
372 372
             memcpy( local_seq, seq + S[i].pos - R, (L+1+R)*sizeof(char) );
373 373
             seqrc( local_seq, L+1+R );
374 374
         }
375 375
         else {
376
-            if( S[i].pos < L ) continue;
376
+            if( S[i].pos < L || S[i].pos >= seqlen - R ) continue;
377 377
             memcpy( local_seq, seq + (S[i].pos-L), (L+1+R)*sizeof(char) );
378 378
         }
379 379
 
... ...
@@ -388,12 +388,12 @@ void sequencing_bias::build( const char* ref_fn,
388 388
             bg_pos = S[i].pos + (pos)ceil( rand_trunc_gauss( offset_std, -100, 100 ) );
389 389
 
390 390
             if( S[i].strand ) {
391
-                if( bg_pos < R ) continue;
391
+                if( bg_pos < R || S[i].pos >= seqlen - L ) continue;
392 392
                 memcpy( local_seq, seq + bg_pos - R, (L+1+R)*sizeof(char) );
393 393
                 seqrc( local_seq, L+1+R );
394 394
             }
395 395
             else {
396
-                if( bg_pos < L ) continue;
396
+                if( bg_pos < L || S[i].pos >= seqlen - R ) continue;
397 397
                 memcpy( local_seq, seq + (bg_pos-L), (L+1+R)*sizeof(char) );
398 398
             }
399 399