This is the mail archive of the glibc-bugs@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug libc/12373] New: FD_SET macro gives warning with -Wconversion (with solution)


http://sourceware.org/bugzilla/show_bug.cgi?id=12373

           Summary: FD_SET macro gives warning with -Wconversion (with
                    solution)
           Product: glibc
           Version: 2.11
            Status: NEW
          Severity: normal
          Priority: P2
         Component: libc
        AssignedTo: drepper.fsp@gmail.com
        ReportedBy: johan162@gmail.com


It is not possible to compile the following code with gcc 4.4.1 and extra
warnings enabled without warning

#include <sys/select.h>
int main(void)
{
    fd_set fds;
    int    fd = 0;
    FD_ZERO(&fds);
    FD_SET(fd, &fds);
    return 0;
}

Compiling this:

gcc -Werror -Wconversion wtst.c
cc1: warnings being treated as errors
wtst.c: In function âmainâ:
wtst.c:8: error: conversion to âunsigned intâ from âintâ may change the sign of
the result
wtst.c:8: error: conversion to âunsigned intâ from âintâ may change the sign of
the result

gcc --version
gcc (SUSE Linux) 4.4.1 [gcc-4_4-branch revision 150839]

The problem stems from the inline assmebler expansion where there is type of fd
clashes with the return type of the sizeof() operator.

This can easily be corrected by changing the macro from the existing:

  __asm__ __volatile__ ("btsl %1,%0" : "=m" (((&fds)->__fds_bits)[((fd) / (8 *
sizeof (__fd_mask)))]) : "r" (((int) (fd)) % (8 * sizeof (__fd_mask))) :
"cc","memory");

to

  __asm__ __volatile__ ("btsl %1,%0" : "=m"
(((&fds)->__fds_bits)[((unsigned)(fd) / (8 * sizeof (__fd_mask)))]) : "r"
(((unsigned) (fd)) % (8 * sizeof (__fd_mask))) : "cc","memory");

-- 
Configure bugmail: http://sourceware.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]