Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 10 Oct 2002 18:37:14 -0700 (PDT)
From:      Lamont Granquist <lamont@scriptkiddie.org>
To:        freebsd-gnats-submit@FreeBSD.org
Subject:   misc/43905: kqueues:   EV_SET(kevp++, ...) is non-intuitive
Message-ID:  <200210110137.g9B1bENM017363@www.freebsd.org>

next in thread | raw e-mail | index | archive | help


>Number:         43905
>Category:       misc
>Synopsis:       kqueues:   EV_SET(kevp++, ...) is non-intuitive
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Oct 10 18:40:02 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     Lamont Granquist
>Release:        5.0-current Sept 29, 2002
>Organization:
>Environment:
> uname -a
FreeBSD coredump.scriptkiddie.org 5.0-CURRENT FreeBSD 5.0-CURRENT #14: Sun Sep 29 21:38:54 PDT 2002     lamont@coredump.scriptkiddie.org:/usr/obj/usr/src/sys/COREDUMP  i386
  
>Description:
EV_SET() macro call references the first argument 6 times making calls like EV_SET(kevp++, [...]); not work as-expected and violates principle of least-surprise.
>How-To-Repeat:
#include <sys/types.h>
#include <sys/event.h>
#include <stdio.h>
#include <stdlib.h>

int main(void) {
        int i;
        struct kevent *kevp = (struct kevent *) malloc(sizeof(struct kevent) * 100);
        for(i = 0; i < 7; i++) {
                printf("%d %p\n", i, kevp + i);
        }
        printf("%p\n", kevp);
        EV_SET(kevp++, 0, EVFILT_READ, EV_ADD, 0, 0, 0);
        printf("%p\n", kevp);
        exit(0);
}


>Fix:
best i can suggest is to convert to an inline function:

static __inline void EV_SET(struct kevent *kevp, const uintptr_t ident, const short filter, const u_short flags, const u_int fflags, const intptr_t data, void * const udata) 
{
        (kevp)->ident = ident;
        (kevp)->filter = filter;
        (kevp)->flags = flags;
        (kevp)->fflags = fflags;
        (kevp)->data = data;
        (kevp)->udata = udata;
}

You could introduce a temporary variable in the EV_SET macro, but things get interesting if there's a namespace collision between that temporary variable and the first argument to EV_SET().

>Release-Note:
>Audit-Trail:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200210110137.g9B1bENM017363>