On Mon, Nov 16, 2015 at 9:03 AM, Philip Guenther <[email protected]> wrote:

> >> integers of different signs: 'unsigned long' and 'int' [-Wsign-compare]
> >>             >= getdtablesize()) {
> >>             ^  ~~~~~~~~~~~~~~~
> >> 1 warning generated.
>
> Out of curiousity, in your experience how often is that warning a real
> issue versus a false positive?  In this case it's a false positive and
> the code is safe.
>
>
I don't encounter that warning very often, so I cannot say.
I agree with you that in this particular case it looks like a false
positive.


>
> In the full expression:
>         if (getdtablecount() + imsg_fd_overhead +
>             (CMSG_SPACE(sizeof(int))-CMSG_SPACE(0))/sizeof(int)
>             >= getdtablesize()) {
>
> the type of unsigned long just be from the CMSG_SPACE() term; if
> keeping that warning option is felt to be a net positive, I would
> suggest casting to int just the CMSG-CMSG/sizeof term.



I tried the following and was able to compile without warning:

Index: imsg.c
===================================================================
--- imsg.c      (revision 290924)
+++ imsg.c      (working copy)
@@ -74,7 +74,7 @@

 again:
        if (getdtablecount() + imsg_fd_overhead +
-           (CMSG_SPACE(sizeof(int))-CMSG_SPACE(0))/sizeof(int)
+           (int)((CMSG_SPACE(sizeof(int))-CMSG_SPACE(0))/sizeof(int))
            >= getdtablesize()) {
                errno = EAGAIN;
                free(ifd);

The cast looks OK to me.  I can commit this to FreeBSD.
Is something that OpenBSD would want to take?
--
Craig

Reply via email to