mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] Musl's FD_{SET,ISSET,CLR} macros from sys/select.h trigger gcc's -Wsign-conversion warnings
@ 2020-08-02 18:24 Petr Skocik
  2020-08-02 18:53 ` Alexander Monakov
  0 siblings, 1 reply; 6+ messages in thread
From: Petr Skocik @ 2020-08-02 18:24 UTC (permalink / raw)
  To: musl

Example:

#include <sys/select.h>
void f(int X)
{
    fd_set set;
    FD_ZERO(&set);
    FD_SET(X,&set);
    FD_CLR(X+1,&set);
    (void)FD_ISSET(X+2,&set);
}

results in

fds.c: In function ‘f’: fds.c:17:2: warning: conversion to ‘long
unsigned int’ from ‘int’ may change the sign of the result
[-Wsign-conversion] 17 | FD_SET(X,&set); | ^~~~~~ fds.c:17:2: warning:
conversion to ‘long unsigned int’ from ‘int’ may change the sign of the
result [-Wsign-conversion] fds.c:18:2: warning: conversion to ‘long
unsigned int’ from ‘int’ may change the sign of the result
[-Wsign-conversion] 18 | FD_CLR(X+1,&set); | ^~~~~~ fds.c:18:2: warning:
conversion to ‘long unsigned int’ from ‘int’ may change the sign of the
result [-Wsign-conversion] fds.c:19:8: warning: conversion to ‘long
unsigned int’ from ‘int’ may change the sign of the result
[-Wsign-conversion] 19 | (void)FD_ISSET(X+2,&set); | ^~~~~~~~
fds.c:19:8: warning: conversion to ‘long unsigned int’ from ‘int’ may
change the sign of the result [-Wsign-conversion]

on `gcc -Wconversion`.

Adding an int-cast before each `sizeof` in the definition of these
macros eliminates the warning:

    #define FD_SET(d, s)   ((s)->fds_bits[(d)/(8*(int)sizeof(long))] |=
(1UL<<((d)%(8*(int)sizeof(long)))))
    #define FD_CLR(d, s)   ((s)->fds_bits[(d)/(8*(int)sizeof(long))] &=
~(1UL<<((d)%(8*(int)sizeof(long)))))
    #define FD_ISSET(d, s) !!((s)->fds_bits[(d)/(8*(int)sizeof(long))] &
(1UL<<((d)%(8*(int)sizeof(long)))))

You might want to add them.

Regards,
Petr Skocik



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

end of thread, other threads:[~2020-08-03 17:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-02 18:24 [musl] Musl's FD_{SET,ISSET,CLR} macros from sys/select.h trigger gcc's -Wsign-conversion warnings Petr Skocik
2020-08-02 18:53 ` Alexander Monakov
2020-08-02 18:56   ` Alexander Monakov
2020-08-02 19:43   ` Petr Skocik
2020-08-03  5:43     ` Markus Wichmann
2020-08-03 17:47       ` Rich Felker

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).