comparison scripts/testfun/demo.m @ 14066:80bda7c4f012 stable

Avoid segfault in test() and demo() blocks with embedded functions (Bugs #35068, #32843, #33981) * test.m, demo.m: Search code block to be executed for any embedded functions. Return an error if any functions found without executing the code block to avoid segmentation fault.
author Rik <octave@nomad.inbox5.com>
date Sun, 18 Dec 2011 18:15:18 -0800
parents e81ddf9cacd5
children 72c96de7a403
comparison
equal deleted inserted replaced
14065:3709aaf73715 14066:80bda7c4f012
120 endif 120 endif
121 121
122 ## Process each demo without failing 122 ## Process each demo without failing
123 try 123 try
124 block = code(idx(doidx(i)):idx(doidx(i)+1)-1); 124 block = code(idx(doidx(i)):idx(doidx(i)+1)-1);
125 ## Use an environment without variables 125 ## FIXME: need to check for embedded test functions, which cause
126 eval (cstrcat ("function __demo__()\n", block, "\nendfunction")); 126 ## segfaults, until issues with subfunctions in functions are resolved.
127 ## Display the code that will be executed before executing it 127 embed_func = regexp (block, '^\s*function ', 'once', 'lineanchors');
128 printf ("%s example %d:%s\n\n", name, doidx(i), block); 128 if (isempty (embed_func))
129 __demo__; 129 ## Use an environment without variables
130 eval (cstrcat ("function __demo__()\n", block, "\nendfunction"));
131 ## Display the code that will be executed before executing it
132 printf ("%s example %d:%s\n\n", name, doidx(i), block);
133 __demo__;
134 else
135 error (["Functions embedded in %!demo blocks are not allowed.\n", ...
136 "Use the %!function/%!endfunction syntax instead to define shared functions for testing.\n"]);
137 endif
130 catch 138 catch
131 ## Let the programmer know which demo failed. 139 ## Let the programmer know which demo failed.
132 printf ("%s example %d: failed\n%s\n", name, doidx(i), lasterr ()); 140 printf ("%s example %d: failed\n%s\n", name, doidx(i), lasterr ());
133 end_try_catch 141 end_try_catch
134 clear __demo__; 142 clear __demo__;