From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Jan =?UTF-8?Q?Dj=C3=A4rv?= Newsgroups: gmane.emacs.bugs Subject: bug#11508: 24.1.50; Off-by-one error in xg_select? Date: Sat, 19 May 2012 10:05:57 +0200 Message-ID: <3B902B7C-C59A-4933-A6AA-E23DB052704C@swipnet.se> References: <4FB64B05.6020709@cornell.edu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 (Apple Message framework v1278) Content-Type: text/plain; charset=iso-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1337414811 18702 80.91.229.3 (19 May 2012 08:06:51 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 19 May 2012 08:06:51 +0000 (UTC) Cc: 11508@debbugs.gnu.org To: Ken Brown Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat May 19 10:06:49 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1SVegU-0003qo-Ud for geb-bug-gnu-emacs@m.gmane.org; Sat, 19 May 2012 10:06:43 +0200 Original-Received: from localhost ([::1]:33937 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SVegU-0008Bh-Aq for geb-bug-gnu-emacs@m.gmane.org; Sat, 19 May 2012 04:06:42 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:45090) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SVegR-0008B8-8r for bug-gnu-emacs@gnu.org; Sat, 19 May 2012 04:06:40 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SVegP-0002Du-79 for bug-gnu-emacs@gnu.org; Sat, 19 May 2012 04:06:38 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:52288) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SVegP-0002Dp-3W for bug-gnu-emacs@gnu.org; Sat, 19 May 2012 04:06:37 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1SVegn-0003BZ-RD for bug-gnu-emacs@gnu.org; Sat, 19 May 2012 04:07:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Jan =?UTF-8?Q?Dj=C3=A4rv?= Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 19 May 2012 08:07:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 11508 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 11508-submit@debbugs.gnu.org id=B11508.133741479212205 (code B ref 11508); Sat, 19 May 2012 08:07:01 +0000 Original-Received: (at 11508) by debbugs.gnu.org; 19 May 2012 08:06:32 +0000 Original-Received: from localhost ([127.0.0.1]:33601 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SVegJ-0003Ao-T2 for submit@debbugs.gnu.org; Sat, 19 May 2012 04:06:32 -0400 Original-Received: from mailout.melmac.se ([62.20.26.67]:55928) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SVegH-0003AU-IW for 11508@debbugs.gnu.org; Sat, 19 May 2012 04:06:30 -0400 Original-Received: from mail01.melmac.se (mail01.melmac.se [62.20.26.80]) by mailout.melmac.se (Postfix) with ESMTP id 46BA99140 for <11508@debbugs.gnu.org>; Sat, 19 May 2012 10:05:57 +0200 (CEST) Original-Received: (qmail 2692 invoked by uid 89); 19 May 2012 09:01:40 -0000 Original-Received: from h-46-59-42-18.na.cust.bahnhof.se (HELO coolsville.localdomain) (boel.djarv@bdtv.se@46.59.42.18) by mail01.melmac.se with ESMTPA; 19 May 2012 09:01:40 -0000 Original-Received: from [172.20.199.13] (zeplin [172.20.199.13]) by coolsville.localdomain (Postfix) with ESMTPSA id A5F797FA06C; Sat, 19 May 2012 10:05:56 +0200 (CEST) In-Reply-To: <4FB64B05.6020709@cornell.edu> X-Mailer: Apple Mail (2.1278) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:60206 Archived-At: Hello. I think you misunderstand how select works. Here is a snippet from the = BSD man page: "The first nfds descriptors are checked in each set; i.e., the descriptors from 0 through nfds-1 in the = descriptor sets are examined. (Example: If you have set two file descriptors = "4" and "17", nfds should not be "2", but rather "17 + 1" or "18".) " Jan D. 18 maj 2012 kl. 15:13 skrev Ken Brown: > I apologize in advance for the noise if I'm misunderstanding = something, > but it seems to me that there is an error in the calculation of the > first argument in the call to select in xgselect.c:105. (Line numbers > refer to the current trunk; xgselect.c was last changed in bzr revno > 108249.) >=20 > The parameter "max_fds" in xg_select, in spite of its name, is = initially > 1 higher than the maximal file descriptor in the fd_sets in the other > parameters. If max_fds doesn't get increased in line 78 or 83, then > line 104 does the wrong thing, causing the first argument to select in > line 105 to be 1 higher than it should be. >=20 > I think the following patch fixes this. It also renames "max_fds" to > "fds_lim" to more accurately reflect what it represents. >=20 > =3D=3D=3D modified file 'src/xgselect.c' > --- src/xgselect.c 2012-05-16 02:22:53 +0000 > +++ src/xgselect.c 2012-05-18 12:28:27 +0000 > @@ -32,7 +32,7 @@ > static ptrdiff_t gfds_size; >=20 > int > -xg_select (int max_fds, SELECT_TYPE *rfds, SELECT_TYPE *wfds, = SELECT_TYPE *efds, > +xg_select (int fds_lim, SELECT_TYPE *rfds, SELECT_TYPE *wfds, = SELECT_TYPE *efds, > EMACS_TIME *timeout) > { > SELECT_TYPE all_rfds, all_wfds; > @@ -41,10 +41,10 @@ > GMainContext *context; > int have_wfds =3D wfds !=3D NULL; > int n_gfds =3D 0, our_tmo =3D 0, retval =3D 0, our_fds =3D 0; > - int i, nfds, fds_lim, tmo_in_millisec; > + int i, nfds, tmo_in_millisec; >=20 > if (inhibit_window_system || !display_arg) > - return select (max_fds, rfds, wfds, efds, timeout); > + return select (fds_lim, rfds, wfds, efds, timeout); >=20 > if (rfds) memcpy (&all_rfds, rfds, sizeof (all_rfds)); > else FD_ZERO (&all_rfds); > @@ -75,12 +75,12 @@ > if (gfds[i].events & G_IO_IN) > { > FD_SET (gfds[i].fd, &all_rfds); > - if (gfds[i].fd > max_fds) max_fds =3D gfds[i].fd; > + if (gfds[i].fd >=3D fds_lim) fds_lim =3D gfds[i].fd + 1; > } > if (gfds[i].events & G_IO_OUT) > { > FD_SET (gfds[i].fd, &all_wfds); > - if (gfds[i].fd > max_fds) max_fds =3D gfds[i].fd; > + if (gfds[i].fd >=3D fds_lim) fds_lim =3D gfds[i].fd + 1; > have_wfds =3D 1; > } > } > @@ -101,7 +101,6 @@ > if (our_tmo) tmop =3D &tmo; > } >=20 > - fds_lim =3D max_fds + 1; > nfds =3D select (fds_lim, &all_rfds, have_wfds ? &all_wfds : NULL, = efds, tmop); >=20 > if (nfds < 0) >=20 >=20 >=20 >=20