git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 06/14] match-trees.c: Initialise variables to suppress msvc warnings

From
Ramsay Jones <ramsay@ramsay1.demon.co.uk>
Date
Dec 4, 2010, 19:05 UTC
Message-ID
<4CFA910B.6040708@ramsay1.demon.co.uk>

The msvc compiler thinks that several variables could be used while uninitialised and issues 12 warnings like:

    ...\git\match-trees.c(75) : warning C4700: uninitialized local \
        variable 'elem1' used
    ...\git\match-trees.c(76) : warning C4700: uninitialized local \
        variable 'elem2' used
    ...\git\match-trees.c(77) : warning C4700: uninitialized local \
        variable 'path1' used
    ...\git\match-trees.c(78) : warning C4700: uninitialized local \
        variable 'path2' used
    ...\git\match-trees.c(79) : warning C4700: uninitialized local \
        variable 'mode1' used
    ...\git\match-trees.c(80) : warning C4700: uninitialized local \
        variable 'mode2' used

In order to suppress the warnings, we simply initialise the char pointer variables to NULL and the int variables to zero.

Signed-off-by: Ramsay Jones <ramsay@ramsay1.demon.co.uk>
---
 match-trees.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)
diff --git a/match-trees.c b/match-trees.c
index 26f7ed1..de050d0 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -72,12 +72,12 @@ static int score_trees(const unsigned char *hash1, const unsigned char *hash2)
 		die("%s is not a tree", sha1_to_hex(hash2));
 	init_tree_desc(&two, two_buf, size);
 	while (one.size | two.size) {
-		const unsigned char *elem1 = elem1;
-		const unsigned char *elem2 = elem2;
-		const char *path1 = path1;
-		const char *path2 = path2;
-		unsigned mode1 = mode1;
-		unsigned mode2 = mode2;
+		const unsigned char *elem1 = NULL;
+		const unsigned char *elem2 = NULL;
+		const char *path1 = NULL;
+		const char *path2 = NULL;
+		unsigned mode1 = 0;
+		unsigned mode2 = 0;
 		int cmp;
 
 		if (one.size)
-- 
1.7.3
Message 1 of 1 in “match-trees.c: Initialise variables to suppress msvc warnings”
  1. 06/14 match-trees.c: Initialise variables to suppress msvc warningsRamsay Jones, Dec 4, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.