[Libguestfs] [PATCH] tests: c-api: do not crash w/ missing hash entry
Richard W.M. Jones
rjones at redhat.com
Fri Aug 8 18:26:55 UTC 2014
On Fri, Aug 08, 2014 at 03:02:49PM +0200, Pino Toscano wrote:
> If an hash does not have the requested key, just error out cleanly
> instead of crashing when trying to compare a null string.
> ---
> tests/c-api/tests-main.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> diff --git a/tests/c-api/tests-main.c b/tests/c-api/tests-main.c
> index 49d36b9..e2e86f5 100644
> --- a/tests/c-api/tests-main.c
> +++ b/tests/c-api/tests-main.c
> @@ -321,6 +321,11 @@ check_hash (char **ret, const char *key, const char *expected)
> {
> const char *value = get_key (ret, key);
>
> + if (value == NULL) {
> + fprintf (stderr, "test failed: hash key %s not found\n", key);
> + return -1;
> + }
> +
> if (STRNEQ (value, expected)) {
> fprintf (stderr, "test failed: hash key %s = \"%s\" is not expected value \"%s\"\n",
> key, value, expected);
> --
> 1.9.3
ACK.
Rich.
--
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
Fedora Windows cross-compiler. Compile Windows programs, test, and
build Windows installers. Over 100 libraries supported.
http://fedoraproject.org/wiki/MinGW
More information about the Libguestfs
mailing list