[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #57284] Crash in MEX file when outputs are not

From: Rik
Subject: [Octave-bug-tracker] [bug #57284] Crash in MEX file when outputs are not used
Date: Thu, 21 Nov 2019 13:19:36 -0500 (EST)
User-agent: Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko

Follow-up Comment #13, bug #57284 (project octave):

For consistency, if we are not expecting programmers to check the number of
outputs before using them then we should do something similar for inputs. 
Here is a small file "mexin.c" that sums its inputs.

#include "mex.h"

void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
  int count = mxGetScalar (prhs[0]);

  double sum = 0.0;
  for (int i = 1; i <= count; i++)
    sum += mxGetScalar (prhs[i]);

  plhs[0] = mxCreateDoubleScalar (sum);

It is a pretty common problem that programmers can't imagine that their
function would be called in the wrong way, and don't put any input validation
to verify their assumptions.  For example, a function named "add_two_numbers"
is likely meant to be called as "add_two_numbers (a, b)".  But you know that
somewhere, at sometime, someone is going to get it wrong. 

Unlike the output case, I get a segfault on the input whenever I exceed nrhs
by even 1. 

mexin (2, 1)
fatal: caught signal Segmentation fault -- stopping myself...
Segmentation fault (core dumped)

(file #47918)

Additional Item Attachment:

File name: mexin.c                        Size:0 KB


Reply to this item at:


  Message sent via Savannah

reply via email to

[Prev in Thread] Current Thread [Next in Thread]