{"thread":{"id":"21117","subject":"[PATCH] MSVC: fix build warnings","startedAt":"2009-10-02T21:40:08Z","lastAt":"2009-10-05T06:31:21Z","messageCount":6,"participants":["Michael Wookey","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"124149","messageId":"d2e97e800910021440q46bd46c4y8a5af987620ffc5c@mail.gmail.com","threadId":"21117","inReplyTo":null,"subject":"[PATCH] MSVC: fix build warnings","fromName":"Michael Wookey","fromEmail":"michaelwookey@gmail.com","sentAt":"2009-10-02T21:40:08Z","receivedAt":"2009-10-02T21:40:08Z","isPatch":true,"sender":{"key":"michaelwookey@gmail.com","avatar":"https://avatars.githubusercontent.com/u/19476?v=4"},"body":"When building with MSVC, the following warnings are issued:\n\n  warning C4700: uninitialized local variable 'xxx' used\n\nWhere 'xxx' is the name of the uninitialised variable that is being used\nto initialise another variable. In all instances, the variable 'xxx' is\nbeing used to initialise itself. Remove the use of initialising a\nvariable with itself to suppress these warnings with MSVC.\n\nSome of these variables require an initial value. This is to prevent gcc\nfrom issuing a warning about a variable being used before it has been\ninitialised. Suppress these gcc warnings by explicitly initialising the\nrequired variables.\n\nSigned-off-by: Michael Wookey <michaelwookey@gmail.com>\n---\nThis patch is but a small step in removing the build warnings that are\ngenerated when compiling with MSVC.\n\n builtin-branch.c      |    2 +-\n builtin-cat-file.c    |    2 +-\n builtin-fast-export.c |    2 +-\n builtin-fetch--tool.c |    4 ++--\n builtin-rev-list.c    |    2 +-\n fast-import.c         |    4 ++--\n match-trees.c         |   12 ++++++------\n merge-recursive.c     |    2 +-\n run-command.c         |    2 +-\n transport.c           |    2 +-\n wt-status.c           |    2 +-\n 11 files changed, 18 insertions(+), 18 deletions(-)\n\ndiff --git a/builtin-branch.c b/builtin-branch.c\nindex 9f57992..cf6a9ca 100644\n--- a/builtin-branch.c\n+++ b/builtin-branch.c\n@@ -93,7 +93,7 @@ static const char *branch_get_color(enum color_branch ix)\n\n static int delete_branches(int argc, const char **argv, int force, int kinds)\n {\n-\tstruct commit *rev, *head_rev = head_rev;\n+\tstruct commit *rev, *head_rev;\n \tunsigned char sha1[20];\n \tchar *name = NULL;\n \tconst char *fmt, *remote;\ndiff --git a/builtin-cat-file.c b/builtin-cat-file.c\nindex 5906842..669608a 100644\n--- a/builtin-cat-file.c\n+++ b/builtin-cat-file.c\n@@ -152,7 +152,7 @@ static int batch_one_object(const char *obj_name,\nint print_contents)\n \tunsigned char sha1[20];\n \tenum object_type type = 0;\n \tunsigned long size;\n-\tvoid *contents = contents;\n+\tvoid *contents;\n\n \tif (!obj_name)\n \t   return 1;\ndiff --git a/builtin-fast-export.c b/builtin-fast-export.c\nindex b0a4029..07e41ea 100644\n--- a/builtin-fast-export.c\n+++ b/builtin-fast-export.c\n@@ -422,7 +422,7 @@ static void get_tags_and_duplicates(struct\nobject_array *pending,\n \tfor (i = 0; i < pending->nr; i++) {\n \t\tstruct object_array_entry *e = pending->objects + i;\n \t\tunsigned char sha1[20];\n-\t\tstruct commit *commit = commit;\n+\t\tstruct commit *commit;\n \t\tchar *full_name;\n\n \t\tif (dwim_ref(e->name, strlen(e->name), sha1, &full_name) != 1)\ndiff --git a/builtin-fetch--tool.c b/builtin-fetch--tool.c\nindex 3dbdf7a..8463f66 100644\n--- a/builtin-fetch--tool.c\n+++ b/builtin-fetch--tool.c\n@@ -416,14 +416,14 @@ static int expand_refs_wildcard(const char\n*ls_remote_result, int numrefs,\n static int pick_rref(int sha1_only, const char *rref, const char\n*ls_remote_result)\n {\n \tint err = 0;\n-\tint lrr_count = lrr_count, i, pass;\n+\tint lrr_count, i, pass;\n \tconst char *cp;\n \tstruct lrr {\n \t\tconst char *line;\n \t\tconst char *name;\n \t\tint namelen;\n \t\tint shown;\n-\t} *lrr_list = lrr_list;\n+\t} *lrr_list;\n\n \tfor (pass = 0; pass < 2; pass++) {\n \t\t/* pass 0 counts and allocates, pass 1 fills... */\ndiff --git a/builtin-rev-list.c b/builtin-rev-list.c\nindex 4ba1c12..b7b9fe3 100644\n--- a/builtin-rev-list.c\n+++ b/builtin-rev-list.c\n@@ -386,7 +386,7 @@ int cmd_rev_list(int argc, const char **argv,\nconst char *prefix)\n \t\tmark_edges_uninteresting(revs.commits, &revs, show_edge);\n\n \tif (bisect_list) {\n-\t\tint reaches = reaches, all = all;\n+\t\tint reaches, all;\n\n \t\trevs.commits = find_bisection(revs.commits, &reaches, &all,\n \t\t\t\t\t      bisect_find_all);\ndiff --git a/fast-import.c b/fast-import.c\nindex 7ef9865..6ed1602 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -1858,7 +1858,7 @@ static void file_change_m(struct branch *b)\n \tconst char *p = command_buf.buf + 2;\n \tstatic struct strbuf uq = STRBUF_INIT;\n \tconst char *endp;\n-\tstruct object_entry *oe = oe;\n+\tstruct object_entry *oe;\n \tunsigned char sha1[20];\n \tuint16_t mode, inline_data = 0;\n\n@@ -2084,7 +2084,7 @@ static int parse_from(struct branch *b)\n\n static struct hash_list *parse_merge(unsigned int *count)\n {\n-\tstruct hash_list *list = NULL, *n, *e = e;\n+\tstruct hash_list *list = NULL, *n, *e;\n \tconst char *from;\n \tstruct branch *s;\n\ndiff --git a/match-trees.c b/match-trees.c\nindex 0fd6df7..99d559e 100644\n--- a/match-trees.c\n+++ b/match-trees.c\n@@ -72,12 +72,12 @@ static int score_trees(const unsigned char *hash1,\nconst unsigned char *hash2)\n \t\tdie(\"%s is not a tree\", sha1_to_hex(hash2));\n \tinit_tree_desc(&two, two_buf, size);\n \twhile (one.size | two.size) {\n-\t\tconst unsigned char *elem1 = elem1;\n-\t\tconst unsigned char *elem2 = elem2;\n-\t\tconst char *path1 = path1;\n-\t\tconst char *path2 = path2;\n-\t\tunsigned mode1 = mode1;\n-\t\tunsigned mode2 = mode2;\n+\t\tconst unsigned char *elem1 = NULL;\n+\t\tconst unsigned char *elem2 = NULL;\n+\t\tconst char *path1 = NULL;\n+\t\tconst char *path2 = NULL;\n+\t\tunsigned mode1 = 0;\n+\t\tunsigned mode2 = 0;\n \t\tint cmp;\n\n \t\tif (one.size)\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex f55b7eb..8d7de22 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -1267,7 +1267,7 @@ int merge_recursive(struct merge_options *o,\n {\n \tstruct commit_list *iter;\n \tstruct commit *merged_common_ancestors;\n-\tstruct tree *mrtree = mrtree;\n+\tstruct tree *mrtree;\n \tint clean;\n\n \tif (show(o, 4)) {\ndiff --git a/run-command.c b/run-command.c\nindex cf2d8f7..014f723 100644\n--- a/run-command.c\n+++ b/run-command.c\n@@ -19,7 +19,7 @@ int start_command(struct child_process *cmd)\n {\n \tint need_in, need_out, need_err;\n \tint fdin[2], fdout[2], fderr[2];\n-\tint failed_errno = failed_errno;\n+\tint failed_errno;\n\n \t/*\n \t * In case of errors we must keep the promise to close FDs\ndiff --git a/transport.c b/transport.c\nindex 644a30a..c6bb992 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -102,7 +102,7 @@ static void insert_packed_refs(const char\n*packed_refs, struct ref **list)\n \t\treturn;\n\n \tfor (;;) {\n-\t\tint cmp = cmp, len;\n+\t\tint cmp, len;\n\n \t\tif (!fgets(buffer, sizeof(buffer), f)) {\n \t\t\tfclose(f);\ndiff --git a/wt-status.c b/wt-status.c\nindex 38eb245..060ad17 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -133,7 +133,7 @@ static void wt_status_print_change_data(struct wt_status *s,\n {\n \tstruct wt_status_change_data *d = it->util;\n \tconst char *c = color(change_type, s);\n-\tint status = status;\n+\tint status = 0;\n \tchar *one_name;\n \tchar *two_name;\n \tconst char *one, *two;\n-- \n1.6.5.rc2\n"},{"id":"124151","messageId":"7v7hvd4flb.fsf@alter.siamese.dyndns.org","threadId":"21117","inReplyTo":"d2e97e800910021440q46bd46c4y8a5af987620ffc5c@mail.gmail.com","subject":"Re: [PATCH] MSVC: fix build warnings","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-02T22:05:04Z","receivedAt":"2009-10-02T22:05:04Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael Wookey <michaelwookey@gmail.com> writes:\n\n> diff --git a/builtin-branch.c b/builtin-branch.c\n> index 9f57992..cf6a9ca 100644\n> --- a/builtin-branch.c\n> +++ b/builtin-branch.c\n> @@ -93,7 +93,7 @@ static const char *branch_get_color(enum color_branch ix)\n>\n>  static int delete_branches(int argc, const char **argv, int force, int kinds)\n>  {\n> -\tstruct commit *rev, *head_rev = head_rev;\n\nI haven't tried, but the patch may break build with \"gcc -Werror\".\n\nThis is a common and unfortunate idiom to tell the readers of the code\nthat this initialization is unnecessary, gcc is not clever enough to\nnotice and gives warnings, and we are squelching it, knowing what we are\ndoing.\n"},{"id":"124159","messageId":"d2e97e800910021628t13bba313he119ba59babdecee@mail.gmail.com","threadId":"21117","inReplyTo":"7v7hvd4flb.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] MSVC: fix build warnings","fromName":"Michael Wookey","fromEmail":"michaelwookey@gmail.com","sentAt":"2009-10-02T23:28:28Z","receivedAt":"2009-10-02T23:28:28Z","isPatch":true,"sender":{"key":"michaelwookey@gmail.com","avatar":"https://avatars.githubusercontent.com/u/19476?v=4"},"body":"2009/10/3 Junio C Hamano <gitster@pobox.com>:\n> Michael Wookey <michaelwookey@gmail.com> writes:\n>\n>> diff --git a/builtin-branch.c b/builtin-branch.c\n>> index 9f57992..cf6a9ca 100644\n>> --- a/builtin-branch.c\n>> +++ b/builtin-branch.c\n>> @@ -93,7 +93,7 @@ static const char *branch_get_color(enum color_branch ix)\n>>\n>>  static int delete_branches(int argc, const char **argv, int force, int kinds)\n>>  {\n>> -     struct commit *rev, *head_rev = head_rev;\n>\n> I haven't tried, but the patch may break build with \"gcc -Werror\".\n>\n> This is a common and unfortunate idiom to tell the readers of the code\n> that this initialization is unnecessary, gcc is not clever enough to\n> notice and gives warnings, and we are squelching it, knowing what we are\n> doing.\n\nI can't build with -Werror on Ubuntu 9.04 (gcc 4.3.3) because of the following:\n\n  http://article.gmane.org/gmane.comp.version-control.git/127477\n\nWith the current git.rc2, I also get the following warnings:\n\n  builtin-mailinfo.c: In function 'handle_commit_msg':\n  builtin-mailinfo.c:789: warning: ignoring return value of\n'ftruncate', declared with attribute warn_unused_result\n\nIt would be nice to get those warnings removed.\n\nI just tried my patch with gcc 4.2.1 (Mac OSX 10.6) and there are a\nfew warnings that are generated because some of the variables have had\ntheir initial values removed. I can send a V2 if you like, however\nthese variable were initialised that way for a reason and it might not\nbe sensible to clean them up in the way I was proposing.\n\nWhat would be a good method of fixing these warnings now that we have\nthe ability to compile with MSVC? Explicitly initialising the\nvariables (to something sane) or should we start to introduce compiler\nspecific pragmas (ugly...) that aim to clean the various build\nwarnings? I just want to reduce (and eventually remove) all the build\nnoise when building using MSVC.\n\nFrom what I have seen so far, building with MSVC spews out a lot of\nwarnings. I am building with MSVC in both the IDE and from a build\nconsole via:\n\n    devenv git.sln /useenv /build \"Debug|Win32\"\n\nIf you compile using gcc with \"-Wextra\" you will see a similar amount\nof build noise that gets generated. See the following for some\nprevious discussion:\n\n  http://article.gmane.org/gmane.comp.version-control.git/128967\n"},{"id":"124215","messageId":"7v7hvak1ec.fsf@alter.siamese.dyndns.org","threadId":"21117","inReplyTo":"d2e97e800910021628t13bba313he119ba59babdecee@mail.gmail.com","subject":"Re: [PATCH] MSVC: fix build warnings","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-05T02:41:47Z","receivedAt":"2009-10-05T02:41:47Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael Wookey <michaelwookey@gmail.com> writes:\n\n> I can't build with -Werror on Ubuntu 9.04 (gcc 4.3.3) because of the following:\n>\n>   http://article.gmane.org/gmane.comp.version-control.git/127477\n\nI think that has been fixed already while I was away ;-)\n"},{"id":"124218","messageId":"d2e97e800910042238t3ba02d59ud4e7f5b3b2b11183@mail.gmail.com","threadId":"21117","inReplyTo":"7v7hvak1ec.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] MSVC: fix build warnings","fromName":"Michael Wookey","fromEmail":"michaelwookey@gmail.com","sentAt":"2009-10-05T05:38:03Z","receivedAt":"2009-10-05T05:38:03Z","isPatch":true,"sender":{"key":"michaelwookey@gmail.com","avatar":"https://avatars.githubusercontent.com/u/19476?v=4"},"body":"2009/10/5 Junio C Hamano <gitster@pobox.com>:\n> Michael Wookey <michaelwookey@gmail.com> writes:\n>\n>> I can't build with -Werror on Ubuntu 9.04 (gcc 4.3.3) because of the following:\n>>\n>>   http://article.gmane.org/gmane.comp.version-control.git/127477\n>\n> I think that has been fixed already while I was away ;-)\n\nI still get the warning with the current git.git:master (dbc1b1f7) and\ngit.git:next (8ea19b84). Would you consider taking the original patch\nto fix the build warning? Perhaps I should resend the patch as a\n\"partial revert\" of eb3a9dd which introduced this warning as described\nhere:\n\n  http://article.gmane.org/gmane.comp.version-control.git/127519\n\nWhat do you think?\n"},{"id":"124222","messageId":"7vws3afj2e.fsf@alter.siamese.dyndns.org","threadId":"21117","inReplyTo":"d2e97e800910042238t3ba02d59ud4e7f5b3b2b11183@mail.gmail.com","subject":"Re: [PATCH] MSVC: fix build warnings","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-10-05T06:31:21Z","receivedAt":"2009-10-05T06:31:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael Wookey <michaelwookey@gmail.com> writes:\n\n> I still get the warning with the current git.git:master (dbc1b1f7)\n\nHmph, I somehow thought Shawn already applied the patch I sent\n$gmane/129285, but it seems he hasn't.\n"}]}