Skip to content

Commit

Permalink
fix crashing if input is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed May 24, 2020
1 parent bc8349e commit 6a3e038
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
5 changes: 4 additions & 1 deletion src/zmat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]){
unsigned char *outputbuf=NULL;
size_t outputsize=0;
unsigned char * inputstr=(mxIsChar(prhs[0])? (unsigned char *)mxArrayToString(prhs[0]) : (unsigned char *)mxGetData(prhs[0]));
int errcode=zmat_run(inputsize, inputstr, &outputsize, &outputbuf, zipid, &ret, iscompress);
int errcode=0;
if(inputsize>0)
errcode=zmat_run(inputsize, inputstr, &outputsize, &outputbuf, zipid, &ret, iscompress);

if(errcode<0){
if(outputbuf)
free(outputbuf);
Expand Down
12 changes: 1 addition & 11 deletions zmat.m
Original file line number Diff line number Diff line change
Expand Up @@ -91,17 +91,7 @@
zipmethod=varargin{3};
end

if(~isempty(input))
[varargout{1:nargout}]=zipmat(input,iscompress,zipmethod);
else
varargout{1}='';
if(nargout>1)
varargout{2}=struct('type',class(varargin{1}),'size',0,...
'byte',length(typecast(cast(1,class(input)),'uint8')),...
'method',zipmethod,'status',0,'level',iscompress);

end
end
[varargout{1:max(1,nargout)}]=zipmat(input,iscompress,zipmethod);

if(exist('inputinfo','var') && isfield(inputinfo,'type'))
varargout{1}=typecast(varargout{1},inputinfo.type);
Expand Down

0 comments on commit 6a3e038

Please sign in to comment.