From owner-freebsd-bugs Thu Oct 10 18:40: 6 2002 Delivered-To: freebsd-bugs@hub.freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 5833B37B401 for ; Thu, 10 Oct 2002 18:40:03 -0700 (PDT) Received: from freefall.freebsd.org (freefall.freebsd.org [216.136.204.21]) by mx1.FreeBSD.org (Postfix) with ESMTP id 9DF6E43EB1 for ; Thu, 10 Oct 2002 18:40:02 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from freefall.freebsd.org (gnats@localhost [127.0.0.1]) by freefall.freebsd.org (8.12.6/8.12.6) with ESMTP id g9B1e2Co089983 for ; Thu, 10 Oct 2002 18:40:02 -0700 (PDT) (envelope-from gnats@freefall.freebsd.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.12.6/8.12.6/Submit) id g9B1e2Nt089982; Thu, 10 Oct 2002 18:40:02 -0700 (PDT) Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 2C5B537B401 for ; Thu, 10 Oct 2002 18:37:15 -0700 (PDT) Received: from www.freebsd.org (www.freebsd.org [216.136.204.117]) by mx1.FreeBSD.org (Postfix) with ESMTP id DB74143EB7 for ; Thu, 10 Oct 2002 18:37:14 -0700 (PDT) (envelope-from nobody@FreeBSD.org) Received: from www.freebsd.org (localhost [127.0.0.1]) by www.freebsd.org (8.12.6/8.12.6) with ESMTP id g9B1bE7R017364 for ; Thu, 10 Oct 2002 18:37:14 -0700 (PDT) (envelope-from nobody@www.freebsd.org) Received: (from nobody@localhost) by www.freebsd.org (8.12.6/8.12.6/Submit) id g9B1bENM017363; Thu, 10 Oct 2002 18:37:14 -0700 (PDT) Message-Id: <200210110137.g9B1bENM017363@www.freebsd.org> Date: Thu, 10 Oct 2002 18:37:14 -0700 (PDT) From: Lamont Granquist To: freebsd-gnats-submit@FreeBSD.org X-Send-Pr-Version: www-1.0 Subject: misc/43905: kqueues: EV_SET(kevp++, ...) is non-intuitive Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org >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 #include #include #include 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