[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] diffseq: remove useless assignment to "best"
From: |
Jim Meyering |
Subject: |
Re: [PATCH] diffseq: remove useless assignment to "best" |
Date: |
Sat, 21 Nov 2009 15:11:00 +0100 |
Bruno Haible wrote:
> Jim Meyering wrote:
>> At that point "best" is already guaranteed to be zero.
>
> The variable 'best' is used for two different purposes here: for two different
> searches in opposite directions. Therefore it does not increase
> maintainability
> to rely on the result of the first search loop for the initialization of the
> second loop, if the two loops are actually independent. I'm therefore
> applying this follow-up that reduces the scope of the variables.
>
> diffseq: reduce scope of variable 'best'.
> * lib/diffseq.h (diag) [USE_HEURISTIC]: Reduce scope of 'best'
> variable, earlier used for two different purposes.
Hi Bruno,
That's a good alternative.
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.
Since I require warning free compilation with -Wuninitialized,
I am considering this patch. Would you prefer to avoid the
warning in a different manner?
[BTW, I'm sure one can use a condition tighter than "3 <= __GNUC__",
but it's not worth it. Anyone still using gcc-2.x has bigger problems. ]
>From ab929a442a6a705a167696e9974da37b959d04a9 Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sat, 21 Nov 2009 15:05:46 +0100
Subject: [PATCH] diffseq: avoid a spurious warning
* lib/diffseq.h (compareseq) [lint && 3 <= __GNUC__]: Initialize
two members of "part" to avoid used-uninitialized warnings.
---
ChangeLog | 6 ++++++
lib/diffseq.h | 8 +++++++-
2 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index d99d387..cef262e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2009-11-21 Jim Meyering <address@hidden>
+
+ diffseq: avoid a spurious warning
+ * lib/diffseq.h (compareseq) [lint && 3 <= __GNUC__]: Initialize
+ two members of "part" to avoid used-uninitialized warnings.
+
2009-11-21 Bruno Haible <address@hidden>
diffseq: reduce scope of variable 'best'.
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);
--
1.6.5.3.433.g11067
- [PATCH] diffseq: remove useless assignment to "best", Jim Meyering, 2009/11/21
- Re: [PATCH] diffseq: remove useless assignment to "best", Bruno Haible, 2009/11/21
- Re: [PATCH] diffseq: remove useless assignment to "best",
Jim Meyering <=
- Re: uninitialized struct members, Bruno Haible, 2009/11/21
- Re: uninitialized struct members, Jim Meyering, 2009/11/21
- Re: uninitialized struct members, Bruno Haible, 2009/11/21
- Re: uninitialized struct members, Jim Meyering, 2009/11/22
- Re: uninitialized struct members, Bruno Haible, 2009/11/22