ekg2/ekg2 — pull request #47 by porridge (2014-04-19 18:06:59+00:00)
Title: Fix check_ekg2 segfault.

There are a few interesting things here.

1) When I first saw "char **argv = { NULL }" I thought this initializes
argv as a pointer to a one-element array holding a null pointer. I
suspect this was also the intent of the author of this code.

Turns out it's wrong. It actually initializes argv to be just a null
pointer, and is exactly equivalent to "char **argv = NULL". The curly
braces only make sense if the type is an array, and are just ignored
otherwise.

So the first thing was to change argv from char** to char*[] to be able
to use an array initializer.

2) Since char*[] decays into a char** on assignment, one might think
that taking argv (which now is a char*[]) and prepending it with & will
make it decay to a char ***, or at least create a type equivalent to
that. But it doesn't. "&argv" is of type "char * (*)[]" which is
(according to http://www.unixwiz.net/techtips/reading-cdecl.html) a
pointer to an array of pointers to char and (surprise surprise!) causes
both a warning and a crash if I try to pass it as a char*** argument.
It's still a bit of a mystery to me, but looking in GDB it looks like
dereferencing it in g_test_init results in a junk pointer.

3) And finally, recent glib requires the leading element of argv to be
non-null, and crashes otherwise.