Re: [PATCH] Fix segfault on empty else

Daniel Jacobowitz
2006-07-06T13:30:49Z

On Wed, Jun 21, 2006 at 11:50:35AM +0100, Andrew STUBBS wrote:
> How about the attached? It is somewhat tricky trying to reliably
> reproduce the problem without valgrind, as you say.
>
> I have put in a few commands that are intended to run through the same
> code and will, most likely, allocate memory in the same place, in order
> to ensure that the crash occurs. This is a little hopeful, but what else
> can I do?
>
> This works for me, but could you please confirm that it works in your
> setup/host (without the patch to fix the problem of course).

:REVIEWMAIL:

Works fine for me - very clever. This patch is OK. I'd recommend two
changes, at your discretion:

> +send_gdb "if 1\necho true\\n\nelse\necho false\\n\nend\n"

Due to the patterns you're matching, this is safe, but in general it's
bad style to use send_gdb without a matching gdb_expect. If you use
gdb_test with the third argument empty, it will not be registered
as a "test", and no pass message will be issued - unless the test
fails, that is. So this is useful for tests which aren't part of the
testcase, and are always assumed to pass.

> +# with true condition
> +send_gdb "if 1\nelse\nend\necho got here\\n\n"
> +gdb_expect {

gdb_test_multiple is a little nicer here. You can still supply your
own eof handler; the only difference is that it will pick
up other quirky bits like internal error messages (and the default
timeout handler should be fine for you here).

--
Daniel Jacobowitz
CodeSourcery