[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: uninitialized struct members
From: |
Bruno Haible |
Subject: |
Re: uninitialized struct members |
Date: |
Sat, 21 Nov 2009 18:41:39 +0100 |
User-agent: |
KMail/1.9.9 |
Hi Jim,
> While we're on the topic, this is the final warning
> I'm seeing in diffutils with most of "manywarnings" enabled:
>
> In file included from analyze.c:36:
> ../lib/diffseq.h: In function 'compareseq':
> ../lib/diffseq.h:461: warning: 'part.ymid' may be used uninitialized\
> in this function [-Wuninitialized]
> ../lib/diffseq.h:461: warning: 'part.xmid' may be used uninitialized\
> in this function [-Wuninitialized]
>
> Yes, it is spurious.
I'm also having similar warnings in the *list modules and in GNU clisp.
> Since I require warning free compilation with -Wuninitialized,
> I am considering this patch. Would you prefer to avoid the
> warning in a different manner?
Well, I would prefer if the inaccuracy of the warnings be acknowledged by
the GCC developers. Has it already been reported?
> diff --git a/lib/diffseq.h b/lib/diffseq.h
> index 0c1723f..0951807 100644
> --- a/lib/diffseq.h
> +++ b/lib/diffseq.h
> @@ -464,7 +464,13 @@ compareseq (OFFSET xoff, OFFSET xlim, OFFSET yoff,
> OFFSET ylim,
> }
> else
> {
> - struct partition part;
> + struct partition part
> +#if defined lint && 3 <= __GNUC__
> + /* Initialize solely to avoid spurious "may be used uninitialized"
> + warnings from gcc. */
> + = { .xmid = 0, .ymid = 0 }
> +#endif
> + ;
>
> /* Find a point of correspondence in the middle of the vectors. */
> diag (xoff, xlim, yoff, ylim, find_minimal, &part, ctxt);
We already have an IF_LINT macro in this file. Let's extend it so that it can
be used in this case as well. Users GCC < 3.0 will now see more warnings, but
they can upgrade to a newer GCC anyway. This avoids to have #if inside
functions for such a trivial stuff. Applying this:
2009-11-21 Jim Meyering <address@hidden>
Bruno Haible <address@hidden>
diffseq: avoid spurious gcc warnings
* lib/diffseq.h (IF_LINT): Enable only with GCC >= 3.0.
(compareseq): Initialize two members of "part" to avoid used-
uninitialized warnings.
--- lib/diffseq.h.orig 2009-11-21 18:39:58.000000000 +0100
+++ lib/diffseq.h 2009-11-21 18:34:58.000000000 +0100
@@ -68,9 +68,10 @@
# define EARLY_ABORT(ctxt) false
#endif
-/* Use this to suppress gcc's `...may be used before initialized' warnings. */
+/* Use this to suppress gcc's `...may be used before initialized' warnings.
+ The Code argument may contain syntax that assumes GCC 3.0 or newer. */
#ifndef IF_LINT
-# ifdef lint
+# if defined lint && __GNUC__ >= 3
# define IF_LINT(Code) Code
# else
# define IF_LINT(Code) /* empty */
@@ -464,7 +465,7 @@
}
else
{
- struct partition part;
+ struct partition part IF_LINT (= { .xmid = 0, .ymid = 0 });
/* Find a point of correspondence in the middle of the vectors. */
diag (xoff, xlim, yoff, ylim, find_minimal, &part, ctxt);