Error 111: Crash in Script, causes unknown

Posted By: GPEngine

Error 111: Crash in Script, causes unknown - 05/11/15 17:53

The following simple script leads to generic Error 111: Crash in Script.
Code:
#define MAX_POINTS 2000

typedef struct {
  var a;
  var b;
  int c;
} MYST;

function unused(MYST* mysts) {
  mysts[0].c = 0;
}

function run() {
  StartDate = 20120815;
  EndDate = 20120901;
  var ds[MAX_POINTS];
  var es[MAX_POINTS];
  MYST fs[MAX_POINTS];
}



Strangely, the presence of function "unused" is significant (If I remove it, the script does not crash.) This defies all my debugging fu.

What is going on here?
Posted By: jcl

Re: Error 111: Crash in Script, causes unknown - 05/11/15 18:22

A function should not be named "function", or else your code won't compile. But I think you'll also get a stack problem. The stack has limited size and is for local variables - large arrays should be global, or static, or allocated at runtime.
Posted By: GPEngine

Re: Error 111: Crash in Script, causes unknown - 05/11/15 18:49

"int function" was a typo. I meant "function unused"

Regarding stack size, this is really painful.
Posted By: GPEngine

Re: Error 111: Crash in Script, causes unknown - 05/11/15 20:57

This error could be detected using static analysis at compile time.
Short of that, can the error message at least say "Stack Overflow"?
Posted By: jcl

Re: Error 111: Crash in Script, causes unknown - 05/12/15 09:55

In an ideal world, sure, but I know no such intelligent C compiler. Runtime stack checking is supported in debugging mode by some compilers. Normal programs do no stack checking as to my knowledge.
Posted By: GPEngine

Re: Error 111: Crash in Script, causes unknown - 05/13/15 05:45

Hope this helps.
Code:
$ cat star.c
#define MAX_POINTS 2000000

void run() {
  double ds[MAX_POINTS];
  ds[0] = 1.;
}

int main() {
  run();
  return 0;
}
$ gcc -c -fstack-usage star.c
$ cat star.su 
star.c:3:6:run	15999896	static
star.c:8:5:main	16	static
$ ./a.out 
Segmentation fault (core dumped)

$ gcc -c -Wstack-usage=10000 star.c
star.c: In function ‘run’:
star.c:6:1: warning: stack usage is 15999896 bytes [-Wstack-usage=]
 }
 ^

Posted By: jcl

Re: Error 111: Crash in Script, causes unknown - 05/14/15 08:34

Not really: GCC prints here only the size of local variables. I suppose it is difficult, if not impossible, that a compiler can detect when the stack is exceeded. For this it had to analyze the call depth of functions.

Possible would be some sort of warning when the compiler sees something suspicious in the run function, such as a local array.
Posted By: GPEngine

Re: Error 111: Crash in Script, causes unknown - 05/16/15 02:57

Right. I'm not asking for perfect anticipation of the stack usage or live monitoring of the stack. I'm just asking for a sanity check regarding local variables, considering that the stack size Zorro allocates is much smaller than what -- pardon the generalization -- application programmers may be used to.
© 2024 lite-C Forums