From: Ján Tomko Date: Fri, 3 Sep 2021 18:15:46 +0000 (+0200) Subject: tests: esxutils: refactor testParseDatastorePath X-Git-Tag: v7.8.0-rc1~314 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=4b4b44d82c36893c5f846577ea1f680f4391c045;p=thirdparty%2Flibvirt.git tests: esxutils: refactor testParseDatastorePath Reduce variable scope to match their lifetime, use g_auto and remove now pointless labels in favor of direct returns. Signed-off-by: Ján Tomko Reviewed-by: Pavel Hrdina --- diff --git a/tests/esxutilstest.c b/tests/esxutilstest.c index 2e2020006e..bfb35fa356 100644 --- a/tests/esxutilstest.c +++ b/tests/esxutilstest.c @@ -35,21 +35,17 @@ static struct testPath paths[] = { static int testParseDatastorePath(const void *data G_GNUC_UNUSED) { - int result = 0; size_t i; - char *datastoreName = NULL; - char *directoryName = NULL; - char *directoryAndFileName = NULL; for (i = 0; i < G_N_ELEMENTS(paths); ++i) { - VIR_FREE(datastoreName); - VIR_FREE(directoryName); - VIR_FREE(directoryAndFileName); + g_autofree char *datastoreName = NULL; + g_autofree char *directoryName = NULL; + g_autofree char *directoryAndFileName = NULL; if (esxUtil_ParseDatastorePath (paths[i].datastorePath, &datastoreName, &directoryName, &directoryAndFileName) != paths[i].result) { - goto failure; + return -1; } if (paths[i].result < 0) @@ -57,32 +53,22 @@ testParseDatastorePath(const void *data G_GNUC_UNUSED) if (STRNEQ(paths[i].datastoreName, datastoreName)) { virTestDifference(stderr, paths[i].datastoreName, datastoreName); - goto failure; + return -1; } if (STRNEQ(paths[i].directoryName, directoryName)) { virTestDifference(stderr, paths[i].directoryName, directoryName); - goto failure; + return -1; } if (STRNEQ(paths[i].directoryAndFileName, directoryAndFileName)) { virTestDifference(stderr, paths[i].directoryAndFileName, directoryAndFileName); - goto failure; + return -1; } } - cleanup: - VIR_FREE(datastoreName); - VIR_FREE(directoryName); - VIR_FREE(directoryAndFileName); - - return result; - - failure: - result = -1; - - goto cleanup; + return 0; }