Skip to content

Commit df2f814

Browse files
committed
correct the exception-handling of mxGetString
1 parent 3a77d58 commit df2f814

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

matlab/libsvmread.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,9 @@ void read_problem(const char *filename, int nlhs, mxArray *plhs[])
188188
void mexFunction( int nlhs, mxArray *plhs[],
189189
int nrhs, const mxArray *prhs[] )
190190
{
191-
char filename[256];
191+
#define filename_size 256
192+
193+
char filename[filename_size];
192194

193195
if(nrhs != 1 || nlhs != 2)
194196
{
@@ -197,11 +199,9 @@ void mexFunction( int nlhs, mxArray *plhs[],
197199
return;
198200
}
199201

200-
mxGetString(prhs[0], filename, mxGetN(prhs[0]) + 1);
201-
202-
if(filename == NULL)
203-
{
204-
mexPrintf("Error: filename is NULL\n");
202+
if(mxGetString(prhs[0], filename, filename_size) == 1){
203+
mexPrintf("Error: wrong or too long filename\n");
204+
fake_answer(nlhs, plhs);
205205
return;
206206
}
207207

0 commit comments

Comments
 (0)