mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH 1/1] FD_SET() and FD_ISSET() warn on -Wsign-conversion
@ 2024-07-16 14:05 Brad House
  2024-07-18 13:19 ` Szabolcs Nagy
  0 siblings, 1 reply; 20+ messages in thread
From: Brad House @ 2024-07-16 14:05 UTC (permalink / raw)
  To: musl

[-- Attachment #1: Type: text/plain, Size: 2672 bytes --]

I'm the maintainer of c-ares (https://c-ares.org) and have been scanning 
the CI build logs for various systems to catch warnings, and on Alpine 
Linux (which obviously uses musl c) we always get these warnings:

/tmp/cirrus-ci-build/src/lib/ares_event_select.c: In function 
'ares_evsys_select_wait':
/tmp/cirrus-ci-build/src/lib/ares_event_select.c:95:7: warning: 
conversion to 'long unsigned int' from 'ares_socket_t' {aka 'int'} may 
change the sign of the result [-Wsign-conversion]
    95 |       FD_SET(ev->fd, &read_fds);
       |       ^~~~~~
/tmp/cirrus-ci-build/src/lib/ares_event_select.c:95:7: warning: 
conversion to 'long unsigned int' from 'ares_socket_t' {aka 'int'} may 
change the sign of the result [-Wsign-conversion]
/tmp/cirrus-ci-build/src/lib/ares_event_select.c:98:7: warning: 
conversion to 'long unsigned int' from 'ares_socket_t' {aka 'int'} may 
change the sign of the result [-Wsign-conversion]
    98 |       FD_SET(ev->fd, &write_fds);
       |       ^~~~~~
/tmp/cirrus-ci-build/src/lib/ares_event_select.c:98:7: warning: 
conversion to 'long unsigned int' from 'ares_socket_t' {aka 'int'} may 
change the sign of the result [-Wsign-conversion]
/tmp/cirrus-ci-build/src/lib/ares_event_select.c:122:11: warning: 
conversion to 'long unsigned int' from 'ares_socket_t' {aka 'int'} may 
change the sign of the result [-Wsign-conversion]
   122 |       if (FD_ISSET(fdlist[i], &read_fds)) {
       |           ^~~~~~~~
/tmp/cirrus-ci-build/src/lib/ares_event_select.c:122:11: warning: 
conversion to 'long unsigned int' from 'ares_socket_t' {aka 'int'} may 
change the sign of the result [-Wsign-conversion]
/tmp/cirrus-ci-build/src/lib/ares_event_select.c:126:11: warning: 
conversion to 'long unsigned int' from 'ares_socket_t' {aka 'int'} may 
change the sign of the result [-Wsign-conversion]
   126 |       if (FD_ISSET(fdlist[i], &write_fds)) {
       |           ^~~~~~~~
/tmp/cirrus-ci-build/src/lib/ares_event_select.c:126:11: warning: 
conversion to 'long unsigned int' from 'ares_socket_t' {aka 'int'} may 
change the sign of the result [-Wsign-conversion]

full build output: 
https://cirrus-ci.com/task/6416020481507328?logs=main#L401

Sockets / File Descriptors in POSIX are defined as 'int', so it seems 
bad to have the standard C library complain when you pass an 'int' to a 
macro that should be expecting an 'int'.  I know -Wsign-conversion 
probably isn't a common warning flag to test with but its part of our 
default set of warnings.

I've attached a patch that will silence this warning, but otherwise not 
impact the behavior.

-Brad

[-- Attachment #2: musl-fd_set-warning-fix.patch --]
[-- Type: text/plain, Size: 1241 bytes --]

diff --git a/include/sys/select.h b/include/sys/select.h
index b3bab1d5..8982f39b 100644
--- a/include/sys/select.h
+++ b/include/sys/select.h
@@ -24,9 +24,9 @@ typedef struct {
 } fd_set;
 
 #define FD_ZERO(s) do { int __i; unsigned long *__b=(s)->fds_bits; for(__i=sizeof (fd_set)/sizeof (long); __i; __i--) *__b++=0; } while(0)
-#define FD_SET(d, s)   ((s)->fds_bits[(d)/(8*sizeof(long))] |= (1UL<<((d)%(8*sizeof(long)))))
-#define FD_CLR(d, s)   ((s)->fds_bits[(d)/(8*sizeof(long))] &= ~(1UL<<((d)%(8*sizeof(long)))))
-#define FD_ISSET(d, s) !!((s)->fds_bits[(d)/(8*sizeof(long))] & (1UL<<((d)%(8*sizeof(long)))))
+#define FD_SET(d, s)   ((s)->fds_bits[((unsigned int)d)/(8*sizeof(long))] |= (1UL<<(((unsigned int)d)%(8*sizeof(long)))))
+#define FD_CLR(d, s)   ((s)->fds_bits[((unsigned int)d)/(8*sizeof(long))] &= ~(1UL<<(((unsigned int)d)%(8*sizeof(long)))))
+#define FD_ISSET(d, s) !!((s)->fds_bits[((unsigned int)d)/(8*sizeof(long))] & (1UL<<(((unsigned int)d)%(8*sizeof(long)))))
 
 int select (int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, struct timeval *__restrict);
 int pselect (int, fd_set *__restrict, fd_set *__restrict, fd_set *__restrict, const struct timespec *__restrict, const sigset_t *__restrict);

^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2024-08-19 16:00 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-16 14:05 [musl] [PATCH 1/1] FD_SET() and FD_ISSET() warn on -Wsign-conversion Brad House
2024-07-18 13:19 ` Szabolcs Nagy
2024-07-18 15:21   ` Brad House
2024-07-18 16:25     ` Rich Felker
2024-07-18 16:54       ` Thorsten Glaser
2024-07-18 17:31         ` Rich Felker
2024-07-18 17:35           ` Thorsten Glaser
2024-07-18 18:17             ` Rich Felker
2024-08-01 19:06             ` Brad House
2024-08-01 20:00               ` Thorsten Glaser
2024-08-01 20:42               ` Brad House
2024-08-14  0:48                 ` Brad House
2024-08-14 21:21                 ` Rich Felker
2024-08-15 19:58                   ` Brad House
2024-08-19 15:33                     ` Brad House
2024-08-19 16:00                       ` Rich Felker
2024-07-18 19:19       ` Brad House
2024-07-18 22:00         ` Thorsten Glaser
2024-07-19  1:50           ` Rich Felker
2024-07-22 15:17     ` Szabolcs Nagy

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).