From: David Barr <davidb...@google.com>
Date: Fri, 1 Jun 2012 00:41:25 +1000

Without this change, clang complains:

 vcs-svn/svndiff.c:298:3: warning: Assigned value is garbage or undefined
                 off_t pre_off = pre_off; /* stupid GCC... */
                 ^               ~~~~~~~

This code uses an old and common idiom for suppressing an
"uninitialized variable" warning, and clang is wrong to warn about it.
The idiom tells the compiler to leave the variable uninitialized,
which saves a few bytes of code size, and, more importantly, allows
valgrind to check at runtime that the variable is properly initialized
by the time it is used.

But MSVC and clang do not know that idiom, so let's avoid it in
vcs-svn/ code.

Initialize pre_off to -1, a recognizably meaningless value, to allow
future code changes that cause pre_off to be used before it is
initialized to be caught early.

Signed-off-by: David Barr <davidb...@google.com>
Signed-off-by: Jonathan Nieder <jrnie...@gmail.com>
---
Changes since v2:

 - new commit message inspired by the discussion at [2]
 - initialize pre_off to -1 instead of 0

[1] http://thread.gmane.org/gmane.comp.version-control.git/198909/focus=198910
[2] http://thread.gmane.org/gmane.comp.version-control.git/169098/focus=169128

 vcs-svn/svndiff.c |    2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/vcs-svn/svndiff.c b/vcs-svn/svndiff.c
index 1647c1a7..c89d9623 100644
--- a/vcs-svn/svndiff.c
+++ b/vcs-svn/svndiff.c
@@ -295,7 +295,7 @@ int svndiff0_apply(struct line_buffer *delta, off_t 
delta_len,
        if (read_magic(delta, &delta_len))
                return -1;
        while (delta_len) {     /* For each window: */
-               off_t pre_off = pre_off; /* stupid GCC... */
+               off_t pre_off = -1;
                size_t pre_len;
 
                if (read_offset(delta, &pre_off, &delta_len) ||
-- 
1.7.10.4

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to