cjlin1 / libsvm

LIBSVM -- A Library for Support Vector Machines
https://www.csie.ntu.edu.tw/~cjlin/libsvm/
BSD 3-Clause "New" or "Revised" License
4.52k stars 1.64k forks source link

Fix test for empty filename in mexFunction #194

Closed jamesjer closed 1 year ago

jamesjer commented 1 year ago

GCC says:

libsvmread.c: In function 'mexFunction':
libsvmread.c:202:21: warning: the comparison will always evaluate as 'false' for the address of 'filename' will never be NULL [-Waddress]
  202 |         if(filename == NULL)
      |                     ^~
libsvmread.c:191:14: note: 'filename' declared here
  191 |         char filename[256];
      |              ^~~~~~~~
cjlin1 commented 1 year ago

Sorry for the late reply.

We reviewed the situation and realized that the suitable way is to check the return of mxGetString. Please see the diff below. This is committed to the internal git and will be available here in the next release. Many thanks for pointing out the issue.

diff --git a/matlab/libsvmread.c b/matlab/libsvmread.c index 21291df..9c5bf43 100644 --- a/matlab/libsvmread.c +++ b/matlab/libsvmread.c @@ -188,7 +188,9 @@ void read_problem(const char filename, int nlhs, mxArray plhs[]) void mexFunction( int nlhs, mxArray plhs[], int nrhs, const mxArray prhs[] ) {