[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt PATCH 05/14] Remove pointless initializations

On Wed, Sep 23, 2020 at 08:14:54PM +0200, Ján Tomko wrote:
Signed-off-by: Ján Tomko <jtomko redhat com>
src/test/test_driver.c | 2 +-
tests/virnumamock.c    | 2 +-
tests/virrandommock.c  | 2 +-
3 files changed, 3 insertions(+), 3 deletions(-)

As mentioned in the previous patch I do not think they are pointless in the long
run.  I prefer ret, rc, rv and similar to be initialised to error/negative value
and others to their null values (numbers to zero, pointers to NULL etc.) even
though I know this is a very subjective opinion.

If you really want to push for this then it would require making

Of course the compiler can check if the value is used before initialisation.
And I hope all current compilers do that with our warning options.  Except they
cannot check for that if you only pass the address of the value.  I guess these
are fine, but I would not like to create a precedent.

What I think we should do instead is make an exception for defining variables
for iteration in the for loop itself.  I know it's only 21 years since it was
standardised and we want to make sure all the compilers and distros can handle
it... /s

OK, I understand that defining variables in the middle of the function most of
the time clutters the code, but for 'i' and 'j' I, for one, see simply no reason
to disallow that.

diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index d582c207f4..cbbfea6665 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -4354,7 +4354,7 @@ testNodeGetFreePages(virConnectPtr conn G_GNUC_UNUSED,
                     unsigned long long *counts,
                     unsigned int flags)
-    size_t i = 0, j = 0;
+    size_t i, j;
    int x = 6;

    virCheckFlags(0, -1);
diff --git a/tests/virnumamock.c b/tests/virnumamock.c
index 40e18e646e..d39c264a3f 100644
--- a/tests/virnumamock.c
+++ b/tests/virnumamock.c
@@ -130,7 +130,7 @@ virNumaGetPages(int node,
    const int pages_def[] = { 4, 2 * 1024, 1 * 1024 * 1024};
    const int npages_def = G_N_ELEMENTS(pages_def);
-    size_t i = 0;
+    size_t i;

    if (pages_size)
        *pages_size = g_new0(unsigned int, npages_def);
diff --git a/tests/virrandommock.c b/tests/virrandommock.c
index 6dd15213e3..ca0520a5a3 100644
--- a/tests/virrandommock.c
+++ b/tests/virrandommock.c
@@ -69,7 +69,7 @@ int
gnutls_dh_params_generate2(gnutls_dh_params_t dparams,
                           unsigned int bits)
-    int rc = 0;
+    int rc;



Attachment: signature.asc
Description: PGP signature

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]