Skip to content

Commit

Permalink
Prevent out of bounds memory usage
Browse files Browse the repository at this point in the history
  • Loading branch information
dpryan79 committed May 23, 2020
1 parent ba5eb8e commit dfa5206
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion MBias.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void *extractMBias(void *foo) {
Config *config = (Config*) foo;
bam_hdr_t *hdr;
bam_mplp_t iter;
int ret, tid, pos, i, seqlen, rv, o = 0;
int ret, tid, pos = 0, i, seqlen, rv, o = 0;
int32_t bedIdx = 0;
int strand;
int n_plp; //This will need to be modified for multiple input files
Expand Down
3 changes: 3 additions & 0 deletions common.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ void print_version() {
}

inline int isCpG(char *seq, int pos, int seqlen) {
if(pos >= seqlen) return 0;
if(*(seq+pos) == 'C' || *(seq+pos) == 'c') {
if(pos+1 == seqlen) return 0;
if(*(seq+pos+1) == 'G' || *(seq+pos+1) == 'g') return 1;
Expand All @@ -60,6 +61,7 @@ inline int isCpG(char *seq, int pos, int seqlen) {
}

inline int isCHG(char *seq, int pos, int seqlen) {
if(pos >= seqlen) return 0;
if(*(seq+pos) == 'C' || *(seq+pos) == 'c') {
if(pos+2 >= seqlen) return 0;
if(*(seq+pos+2) == 'G' || *(seq+pos+2) == 'g') return 1;
Expand All @@ -73,6 +75,7 @@ inline int isCHG(char *seq, int pos, int seqlen) {
}

inline int isCHH(char *seq, int pos, int seqlen) {
if(pos >= seqlen) return 0;
if(*(seq+pos) == 'C' || *(seq+pos) == 'c') return 1;
else if(*(seq+pos) == 'G' || *(seq+pos) == 'g') return -1;
return 0;
Expand Down

0 comments on commit dfa5206

Please sign in to comment.