Skip to contentSkip to conversation

Fix gcc-4 warning in accept() call

PATCH In review Pavel Roskin 4 participants 8 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Fix gcc-4 warning in accept() call

Fix gcc-4 warning in accept() call

gcc-4 warns about sign mismatch in pointers. Third argument in accept() is socklen_t, which is unsigned. Since Linus doesn't like socklen_t (see commit 7fa090844f7d1624c7d1ffc621aae6aec84a1110), let's use unsigned int.

daemon.c +1 -1
@@ -459,7 +459,7 @@ static int serve(int port)
 
 			if (FD_ISSET(sockfd, &fds)) {
 				struct sockaddr_storage ss;
-				int sslen = sizeof(ss);
+				unsigned int sslen = sizeof(ss);
 				int incoming = accept(sockfd, (struct sockaddr *)&ss, &sslen);
 				if (incoming < 0) {
 					switch (errno) {
Signature · 2 lines
Regards,
Pavel Roskin
#1 lore raw
Quoted 13 lines · Pavel Roskin

Fix gcc-4 warning in accept() call

gcc-4 warns about sign mismatch in pointers. Third argument in accept() is socklen_t, which is unsigned. Since Linus doesn't like socklen_t (see commit 7fa090844f7d1624c7d1ffc621aae6aec84a1110), let's use unsigned int.

daemon.c static int serve(int port) · line 462

Quoted 5 lines
daemon.c +1 -1
@@ -459,7 +459,7 @@ static int serve(int port)
 
 			if (FD_ISSET(sockfd, &fds)) {
 				struct sockaddr_storage ss;
-				int sslen = sizeof(ss);
+				unsigned int sslen = sizeof(ss);

Shouldn't this be size_t?

Quoted 3 lines
daemon.c +0 -0
 				int incoming = accept(sockfd, (struct sockaddr *)&ss, &sslen);
 				if (incoming < 0) {
 					switch (errno) {
Signature · 4 lines
Dr. Horst H. von Brand                   User #22616 counter.li.org
Departamento de Informatica                     Fono: +56 32 654431
Universidad Tecnica Federico Santa Maria              +56 32 654239
Casilla 110-V, Valparaiso, Chile                Fax:  +56 32 797513
#2 lore raw

Quoting Horst von Brand <[email protected]>:

Quoted 3 lines

daemon.c static int serve(int port) · line 462

Quoted 1 line
daemon.c +1 -0
+				unsigned int sslen = sizeof(ss);

Shouldn't this be size_t?

No. That would actually break things on big-endian 64-bit platforms.

You can see "info libc" for the whole story. My (limited!) understanding is that it should be 32-bit for compatibility reasons, so socklen_t was a trick to fool size_t proponents from the POSIX committee :-)

--
Regards,
Pavel Roskin

#3 lore raw
Quoted 8 lines · Pavel Roskin

Quoting Horst von Brand <[email protected]>:

Quoted 3 lines

daemon.c static int serve(int port) · line 462

Quoted 1 line
daemon.c +1 -0
+				unsigned int sslen = sizeof(ss);

Shouldn't this be size_t?

Quoted 6 lines

No. That would actually break things on big-endian 64-bit platforms.

You can see "info libc" for the whole story. My (limited!) understanding is that it should be 32-bit for compatibility reasons, so socklen_t was a trick to fool size_t proponents from the POSIX committee :-)

Formally it should be "socklen_t" or "int". It should *not* be "unsigned int"!

-hpa

#4 lore raw
In reply to Pavel Roskin
Quoted 4 lines · Pavel Roskin

gcc-4 warns about sign mismatch in pointers. Third argument in accept() is socklen_t, which is unsigned. Since Linus doesn't like socklen_t (see commit 7fa090844f7d1624c7d1ffc621aae6aec84a1110), let's use unsigned int.

Based on the list comments, I'd drop this patch -- it appears that gcc-4 warning is useless in this case.

#5 lore raw
Quoted 11 lines · Junio C Hamano
Quoted 4 lines · Pavel Roskin

gcc-4 warns about sign mismatch in pointers. Third argument in accept() is socklen_t, which is unsigned. Since Linus doesn't like socklen_t (see commit 7fa090844f7d1624c7d1ffc621aae6aec84a1110), let's use unsigned int.

Based on the list comments, I'd drop this patch -- it appears that gcc-4 warning is useless in this case.

No, it's not. The proper type, if you don't use socklen_t, is int, not unsigned int.

-hpa

#6 lore raw
Quoted 11 lines · H. Peter Anvin
Quoted 9 lines · Junio C Hamano
Quoted 4 lines · Pavel Roskin

gcc-4 warns about sign mismatch in pointers. Third argument in accept() is socklen_t, which is unsigned. Since Linus doesn't like socklen_t (see commit 7fa090844f7d1624c7d1ffc621aae6aec84a1110), let's use unsigned int.

Quoted 6 lines
Quoted 3 lines

Based on the list comments, I'd drop this patch -- it appears that gcc-4 warning is useless in this case.

No, it's not. The proper type, if you don't use socklen_t, is int, not unsigned int.

Apparently I'm wrong; socklen_t is unsigned int at least on glibc for i386. I'll shut up now.

-hpa

#7 lore raw
Quoted 2 lines · H. Peter Anvin

Apparently I'm wrong; socklen_t is unsigned int at least on glibc for i386. I'll shut up now.

Ah, I should shut up too. Thanks for checking what we should use.