From 4b4b44d82c36893c5f846577ea1f680f4391c045 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Fri, 3 Sep 2021 20:15:46 +0200 Subject: [PATCH] tests: esxutils: refactor testParseDatastorePath MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- tests/esxutilstest.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) 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; }