Skip to contentSkip to conversation

MSVC fixes

PATCH In review Sven Strickroth 4 participants 9 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

cover MSVC fixes

Hi,

I've 3 patches fixing warnings and errors when compiling with latest MSVC (2012).

Signature · 3 lines
Best regards,
 Sven Strickroth
 PGP key id F5A9D4C4 @ any key-server
#1 lore raw

PATCH 1/3 poll.h lies in the same folder, so use normal quotes for include

Some compilers, like Visual C++ complain when <> is used instead of double quotes for non system includes.

---
 compat/poll/poll.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
compat/poll/poll.c +1 -1
index 7d226ec..b85386a 100644
@@ -31,7 +31,7 @@
 #include <sys/types.h>
 
 /* Specification.  */
-#include <poll.h>
+#include "poll.h"
 
 #include <errno.h>
 #include <limits.h>
Signature · 3 lines
Best regards,
 Sven Strickroth
 PGP key id F5A9D4C4 @ any key-server
#2 lore raw

Re: [PATCH 1/3] poll.h lies in the same folder, so use normal quotes for include

Am 09.05.2013 03:12 schrieb Sven Strickroth:

Quoted 2 lines

Some compilers, like Visual C++ complain when <> is used instead of double quotes for non system includes.

I just noticed that this patch isn't necessary for 1.8.3 (since 41f2999180f5a58f2a4214d896359c1587c9024f) any more. Sorry for the noise
- I was still building against 1.8.2.2.

Signature · 3 lines
Best regards,
 Sven Strickroth
 PGP key id F5A9D4C4 @ any key-server
#3 lore raw

PATCH 2/3 mingw.h: Define only if necessary

In reply to Sven Strickroth

Since the latest version of MSVC EWOULDBLOCK, EAFNOSUPPORT and ECONNABORTED are defined in errno.h. When used with MSVC mingw.h is included from msvc.h and causes warnings about redefinitions.

---
 compat/mingw.h | 6 ++++++
 1 file changed, 6 insertions(+)
compat/mingw.h +6 -0
index 685cd2c..c424333 100644
@@ -32,7 +32,9 @@ typedef int socklen_t;
 #define WEXITSTATUS(x) ((x) & 0xff)
 #define WTERMSIG(x) SIGTERM
 
+#ifndef EWOULDBLOCK
 #define EWOULDBLOCK EAGAIN
+#endif
 #define SHUT_WR SD_SEND
 
 #define SIGHUP 1
@@ -46,8 +48,12 @@ typedef int socklen_t;
 #define F_SETFD 2
 #define FD_CLOEXEC 0x1
 
+#ifndef EAFNOSUPPORT
 #define EAFNOSUPPORT WSAEAFNOSUPPORT
+#endif
+#ifndef ECONNABORTED
 #define ECONNABORTED WSAECONNABORTED
+#endif
 
 struct passwd {
 	char *pw_name;
Signature · 3 lines
Best regards,
 Sven Strickroth
 PGP key id F5A9D4C4 @ any key-server
#4 lore raw

PATCH 3/3 Initialize variables with values

In reply to Sven Strickroth

With MSVC initializing a variable with "int a=a" causes a warning about using an uninitialized value.

---
 builtin/rev-list.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/rev-list.c +1 -1
index 67701be..13afacd 100644
@@ -338,7 +338,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
 		mark_edges_uninteresting(revs.commits, &revs, show_edge);
 
 	if (bisect_list) {
-		int reaches = reaches, all = all;
+		int reaches = 0, all = 0;
 
 		revs.commits = find_bisection(revs.commits, &reaches, &all,
 					      bisect_find_all);
Signature · 3 lines
Best regards,
 Sven Strickroth
 PGP key id F5A9D4C4 @ any key-server
#5 lore raw

Re: [PATCH 3/3] Initialize variables with values

Quoted 13 lines · Sven Strickroth

With MSVC initializing a variable with "int a=a" causes a warning about using an uninitialized value.

---
 builtin/rev-list.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/rev-list.c +0 -0
index 67701be..13afacd 100644

builtin/rev-list.c int cmd_rev_list(int argc, const char **argv, const char *prefix) · line 344

Quoted 8 lines
builtin/rev-list.c +1 -1
@@ -338,7 +338,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
 		mark_edges_uninteresting(revs.commits, &revs, show_edge);
 
 	if (bisect_list) {
-		int reaches = reaches, all = all;
+		int reaches = 0, all = 0;
 
 		revs.commits = find_bisection(revs.commits, &reaches, &all,
 					      bisect_find_all);

But this generates worse code, at least using gcc 4.7.2:

new renamed from old +1 -1
@@ -1,2 +1,2 @@
    text	   data	    bss	    dec	    hex	filename
-   4283	      0	      0	   4283	   10bb	builtin/rev-list.o
+   4299	      0	      0	   4299	   10cb	builtin/rev-list.o

Krzysiek

#6 lore raw

Re: [PATCH 3/3] Initialize variables with values

In reply to Sven Strickroth

Hi,

Quoted 2 lines · Sven Strickroth

With MSVC initializing a variable with "int a=a" causes a warning about using an uninitialized value.

[...]

builtin/rev-list.c int cmd_rev_list(int argc, const char **argv, const char *prefix) · line 341

Quoted 8 lines
builtin/rev-list.c +1 -1
@@ -338,7 +338,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
 		mark_edges_uninteresting(revs.commits, &revs, show_edge);
 
 	if (bisect_list) {
-		int reaches = reaches, all = all;
+		int reaches = 0, all = 0;

A correct way to spell this is

		int reaches, all;

which, as a bonus, lets the compiler warn if they are used uninitialized. Does that provoke warnings?

Thanks,
Jonathan

#7 lore raw

Re: [PATCH 3/3] Initialize variables with values

Am 09.05.2013 15:21 schrieb Jonathan Nieder:

Quoted 16 lines
Quoted 2 lines · Sven Strickroth

With MSVC initializing a variable with "int a=a" causes a warning about using an uninitialized value.

[...]

builtin/rev-list.c int cmd_rev_list(int argc, const char **argv, const char *prefix) · line 341

Quoted 8 lines
builtin/rev-list.c +1 -1
@@ -338,7 +338,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
 		mark_edges_uninteresting(revs.commits, &revs, show_edge);
 
 	if (bisect_list) {
-		int reaches = reaches, all = all;
+		int reaches = 0, all = 0;

A correct way to spell this is

Quoted 4 lines
		int reaches, all;

which, as a bonus, lets the compiler warn if they are used uninitialized. Does that provoke warnings?

This seems to be ok.

Signature · 3 lines
Best regards,
 Sven Strickroth
 PGP key id F5A9D4C4 @ any key-server
#8 lore raw

Re: [PATCH 3/3] Initialize variables with values

In reply to Jonathan Nieder

Am 09.05.2013 15:21, schrieb Jonathan Nieder:

Quoted 18 lines

Hi,

Quoted 2 lines · Sven Strickroth

With MSVC initializing a variable with "int a=a" causes a warning about using an uninitialized value.

[...]

builtin/rev-list.c int cmd_rev_list(int argc, const char **argv, const char *prefix) · line 341

Quoted 8 lines
builtin/rev-list.c +1 -1
@@ -338,7 +338,7 @@ int cmd_rev_list(int argc, const char **argv, const char *prefix)
  		mark_edges_uninteresting(revs.commits, &revs, show_edge);
 
  	if (bisect_list) {
-		int reaches = reaches, all = all;
+		int reaches = 0, all = 0;

A correct way to spell this is

Quoted 4 lines
		int reaches, all;

which, as a bonus, lets the compiler warn if they are used uninitialized. Does that provoke warnings?

Only find_bisection() (defined in bisect.c) is used to set these variables in that block. While it sets "all" unconditionally, it doesn't always set "reaches" -- only if it actually finds something. That's still safe because the following code path errors out early if nothing was found before it uses "reaches".

Are there C compilers that can analyse initialization and usage of variables across compilation units like that?

Anyway, initializing the variables to zero makes this code consistent with the second call-site of find_bisection(). Making sure this function sets "reaches" unconditionally as well and dropping the initialization from both places may be even better.

René