git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jonathan Nieder <jrnieder@gmail.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: David Michael Barr <davidbarr@google.com>,
	Florian Achleitner <florian.achleitner2.6.31@gmail.com>,
	git@vger.kernel.org
Subject: [PATCH 2/9] vcs-svn: avoid self-assignment in dummy initialization of pre_off
Date: Fri, 6 Jul 2012 12:16:51 -0500	[thread overview]
Message-ID: <20120706171651.GC31001@burratino> (raw)
In-Reply-To: <20120706171040.GA31001@burratino>

From: David Barr <davidbarr@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 <davidbarr@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@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

  parent reply	other threads:[~2012-07-06 17:17 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-06-06 21:55 What's cooking in git.git (Jun 2012, #02; Wed, 6) Junio C Hamano
2012-06-06 23:49 ` David Michael Barr
2012-06-07  0:39   ` Jonathan Nieder
2012-06-07  5:25     ` Junio C Hamano
2012-07-06 17:10       ` [GIT PULL] vcs-svn housekeeping Jonathan Nieder
2012-07-06 17:13         ` [PATCH 1/9] vcs-svn: drop no-op reset methods Jonathan Nieder
2012-07-06 17:16         ` Jonathan Nieder [this message]
2012-07-06 17:18         ` [PATCH 3/9] vcs-svn: simplify cleanup in apply_one_window Jonathan Nieder
2012-07-06 17:18         ` [PATCH 4/9] vcs-svn: use constcmp instead of prefixcmp Jonathan Nieder
2012-07-06 17:19         ` [PATCH 5/9] vcs-svn: use strstr instead of memmem Jonathan Nieder
2012-07-06 17:21         ` [PATCH 6/9] vcs-svn: suppress signed/unsigned comparison warnings Jonathan Nieder
2012-07-06 17:22         ` [PATCH 7/9] vcs-svn: suppress a signed/unsigned comparison warning Jonathan Nieder
2012-07-06 17:25         ` [PATCH 8/9] " Jonathan Nieder
2012-07-06 17:27         ` [PATCH 9/9] vcs-svn: allow 64-bit Prop-Content-Length Jonathan Nieder
2012-07-06 19:41         ` [GIT PULL] vcs-svn housekeeping David Michael Barr
2012-07-06 20:28           ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20120706171651.GC31001@burratino \
    --to=jrnieder@gmail.com \
    --cc=davidbarr@google.com \
    --cc=florian.achleitner2.6.31@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).