Skip to content

Commit 159b711

Browse files
committed
Fix an array out of bounds error when the input file contains too many motifs.
Fix an array out of bounds error when the input file contains too many motifs. Signed-off-by: Gert Hulselmans <[email protected]>
1 parent 96d0b44 commit 159b711

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

src/PlatformSupport.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,12 @@ int PlatformSupport::ReadTransfacFile(char* fn, bool famNames, bool input, bool
144144
}else{
145145
//Copy the contents of tmp_Motif to a new spot in currMotifs, when the last matrix line is read.
146146
if(curr_cnt != 0){
147+
if(currCnt == MAX_MOTIFS - 1)
148+
{
149+
printf("To many motifs in input file. Increase the value of MAX_MOTIFS in globals.h and recompile.\n");
150+
exit(1);
151+
}
152+
147153
currMotifs[currCnt] = new Motif(curr_cnt);
148154
if(useweighting)
149155
currMotifs[currCnt]->weighting=tmp_Motif->weighting;
@@ -194,6 +200,12 @@ int PlatformSupport::ReadTransfacFile(char* fn, bool famNames, bool input, bool
194200

195201
//Copy the contents of the last tmp_Motif to a new spot in currMotifs, if this was not done yet
196202
if(curr_cnt != 0){
203+
if(currCnt == MAX_MOTIFS - 1)
204+
{
205+
printf("To many motifs in input file. Increase the value of MAX_MOTIFS in globals.h and recompile.\n");
206+
exit(1);
207+
}
208+
197209
currMotifs[currCnt] = new Motif(curr_cnt);
198210
if(useweighting)
199211
currMotifs[currCnt]->weighting=tmp_Motif->weighting;

src/globals.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const int AA=20;
3838
const int STR_LEN = 500;
3939
const int LONG_STR=1000;
4040
const double DFLT_NUM_INSTANCES=30.0;
41-
const int MAX_MOTIFS = 10001;
41+
const int MAX_MOTIFS = 100001;
4242
const int MAX_MOTIF_LEN = 200;
4343
const int MAX_MARKOV = 6;
4444
const int maxLen = 25;

0 commit comments

Comments
 (0)