From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Ken Brown Newsgroups: gmane.emacs.bugs Subject: bug#11508: 24.1.50; Off-by-one error in xg_select? Date: Fri, 18 May 2012 09:13:41 -0400 Message-ID: <4FB64B05.6020709@cornell.edu> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1337346893 14886 80.91.229.3 (18 May 2012 13:14:53 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 18 May 2012 13:14:53 +0000 (UTC) To: 11508@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri May 18 15:14:52 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 1SVN19-0002Yw-Pc for geb-bug-gnu-emacs@m.gmane.org; Fri, 18 May 2012 15:14:52 +0200 Original-Received: from localhost ([::1]:39465 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SVN19-0000Q1-0E for geb-bug-gnu-emacs@m.gmane.org; Fri, 18 May 2012 09:14:51 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:58936) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SVN15-0000Pt-TY for bug-gnu-emacs@gnu.org; Fri, 18 May 2012 09:14:49 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SVN0z-0006WG-Mc for bug-gnu-emacs@gnu.org; Fri, 18 May 2012 09:14:47 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:50831) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SVN0z-0006WB-J7 for bug-gnu-emacs@gnu.org; Fri, 18 May 2012 09:14:41 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1SVN1J-0001AL-UI for bug-gnu-emacs@gnu.org; Fri, 18 May 2012 09:15:01 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Ken Brown Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 18 May 2012 13:15:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 11508 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.13373468884444 (code B ref -1); Fri, 18 May 2012 13:15:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 18 May 2012 13:14:48 +0000 Original-Received: from localhost ([127.0.0.1]:60377 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SVN15-00019c-SV for submit@debbugs.gnu.org; Fri, 18 May 2012 09:14:48 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:34429) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1SVN13-00019N-8B for submit@debbugs.gnu.org; Fri, 18 May 2012 09:14:46 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SVN0b-0006SJ-AJ for submit@debbugs.gnu.org; Fri, 18 May 2012 09:14:18 -0400 Original-Received: from lists.gnu.org ([208.118.235.17]:49041) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SVN0b-0006SE-6b for submit@debbugs.gnu.org; Fri, 18 May 2012 09:14:17 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:58697) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SVN0U-0000OQ-Gt for bug-gnu-emacs@gnu.org; Fri, 18 May 2012 09:14:16 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SVN0S-0006Pw-CV for bug-gnu-emacs@gnu.org; Fri, 18 May 2012 09:14:09 -0400 Original-Received: from limestone5.mail.cornell.edu ([128.253.83.165]:46257) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SVN0S-0006Nv-8F for bug-gnu-emacs@gnu.org; Fri, 18 May 2012 09:14:08 -0400 X-CornellRouted: This message has been Routed already. Original-Received: from soapstone1.mail.cornell.edu (soapstone1.mail.cornell.edu [128.253.83.143]) by limestone5.mail.cornell.edu (8.14.4/8.14.4) with ESMTP id q4IDDt4C016268 for ; Fri, 18 May 2012 09:13:57 -0400 (EDT) Original-Received: from authusersmtp.mail.cornell.edu (granite2.mail.cornell.edu [128.253.83.142]) by soapstone1.mail.cornell.edu (8.14.4/8.14.4) with ESMTP id q4IDDvYO021092 for ; Fri, 18 May 2012 09:13:57 -0400 (EDT) Original-Received: from [192.168.1.4] (cpe-67-249-194-47.twcny.res.rr.com [67.249.194.47]) (authenticated bits=0) by authusersmtp.mail.cornell.edu (8.14.4/8.12.10) with ESMTP id q4IDDpaW029496 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Fri, 18 May 2012 09:13:52 -0400 (EDT) User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20120327 Thunderbird/11.0.1 X-PMX-CORNELL-SPAM-CHECKED: Pawpaw X-PMX-Version: 5.5.9.395186, Antispam-Engine: 2.7.2.376379, Antispam-Data: 2012.5.18.130633 X-Original-Sender: kbrown@cornell.edu - Fri May 18 09:13:52 2012 X-PMX-CORNELL-REASON: CU_White_List_Override X-detected-operating-system: by eggs.gnu.org: Solaris 9 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) 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:60176 Archived-At: 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.) 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. I think the following patch fixes this. It also renames "max_fds" to "fds_lim" to more accurately reflect what it represents. === 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; 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 = wfds != NULL; int n_gfds = 0, our_tmo = 0, retval = 0, our_fds = 0; - int i, nfds, fds_lim, tmo_in_millisec; + int i, nfds, tmo_in_millisec; if (inhibit_window_system || !display_arg) - return select (max_fds, rfds, wfds, efds, timeout); + return select (fds_lim, rfds, wfds, efds, timeout); 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 = gfds[i].fd; + if (gfds[i].fd >= fds_lim) fds_lim = 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 = gfds[i].fd; + if (gfds[i].fd >= fds_lim) fds_lim = gfds[i].fd + 1; have_wfds = 1; } } @@ -101,7 +101,6 @@ if (our_tmo) tmop = &tmo; } - fds_lim = max_fds + 1; nfds = select (fds_lim, &all_rfds, have_wfds ? &all_wfds : NULL, efds, tmop); if (nfds < 0)