@@ -59,7 +59,7 @@ void read_problem(const char *filename, int nlhs, mxArray *plhs[])
5959 int max_index , min_index , inst_max_index ;
6060 size_t elements , k , i , l = 0 ;
6161 FILE * fp = fopen (filename ,"r" );
62- char * endptr ;
62+ char * endptr , * r = ( char * ) NULL ;
6363 mwIndex * ir , * jc ;
6464 double * labels , * samples ;
6565
@@ -83,11 +83,11 @@ void read_problem(const char *filename, int nlhs, mxArray *plhs[])
8383 int index = 0 ;
8484
8585 inst_max_index = -1 ; // strtol gives 0 if wrong format, and precomputed kernel has <index> start from 0
86- strtok (line ," \t" ); // label
86+ strtok_r (line ," \t" , & r ); // label
8787 while (1 )
8888 {
89- idx = strtok (NULL ,":" ); // index:value
90- val = strtok (NULL ," \t" );
89+ idx = strtok_r (NULL ,":" , & r ); // index:value
90+ val = strtok_r (NULL ," \t" , & r );
9191 if (val == NULL )
9292 break ;
9393
@@ -131,7 +131,7 @@ void read_problem(const char *filename, int nlhs, mxArray *plhs[])
131131
132132 readline (fp );
133133
134- label = strtok (line ," \t\n" );
134+ label = strtok_r (line ," \t\n" , & r );
135135 if (label == NULL )
136136 {
137137 mexPrintf ("Empty line at line %d\n" ,i + 1 );
@@ -149,8 +149,8 @@ void read_problem(const char *filename, int nlhs, mxArray *plhs[])
149149 // features
150150 while (1 )
151151 {
152- idx = strtok (NULL ,":" );
153- val = strtok (NULL ," \t" );
152+ idx = strtok_r (NULL ,":" , & r );
153+ val = strtok_r (NULL ," \t" , & r );
154154 if (val == NULL )
155155 break ;
156156
0 commit comments