From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.devel Subject: Re: ptrdiff_t misuse [was :Re: (empty)] Date: Thu, 05 Jul 2012 17:08:50 -0700 Organization: UCLA Computer Science Department Message-ID: <4FF62C92.8090406@cs.ucla.edu> References: <83lij66yq9.fsf@gnu.org> <4FEDB953.1010800@yandex.ru> <4FEEA720.2040405@cs.ucla.edu> <4FEEFBAB.6000404@cs.ucla.edu> <4FF3E1D6.1050103@cs.ucla.edu> <83bojv4h13.fsf@gnu.org> <4FF48920.501@cs.ucla.edu> <83vci22mr0.fsf@gnu.org> <83obnu2e8s.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1341533349 16503 80.91.229.3 (6 Jul 2012 00:09:09 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 6 Jul 2012 00:09:09 +0000 (UTC) Cc: dmantipov@yandex.ru, monnier@iro.umontreal.ca, emacs-devel@gnu.org To: Eli Zaretskii Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Fri Jul 06 02:09:08 2012 Return-path: Envelope-to: ged-emacs-devel@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 1Smw6b-0007rp-Av for ged-emacs-devel@m.gmane.org; Fri, 06 Jul 2012 02:09:05 +0200 Original-Received: from localhost ([::1]:36665 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Smw6a-0004pm-2e for ged-emacs-devel@m.gmane.org; Thu, 05 Jul 2012 20:09:04 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:33265) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Smw6W-0004pY-SB for emacs-devel@gnu.org; Thu, 05 Jul 2012 20:09:02 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Smw6V-0000vn-A6 for emacs-devel@gnu.org; Thu, 05 Jul 2012 20:09:00 -0400 Original-Received: from smtp.cs.ucla.edu ([131.179.128.62]:56661) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Smw6S-0000tU-Gj; Thu, 05 Jul 2012 20:08:56 -0400 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.cs.ucla.edu (Postfix) with ESMTP id 28BBCA6000E; Thu, 5 Jul 2012 17:08:54 -0700 (PDT) X-Virus-Scanned: amavisd-new at smtp.cs.ucla.edu Original-Received: from smtp.cs.ucla.edu ([127.0.0.1]) by localhost (smtp.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3cbXI-KKRA1i; Thu, 5 Jul 2012 17:08:53 -0700 (PDT) Original-Received: from [192.168.1.4] (pool-108-23-119-2.lsanca.fios.verizon.net [108.23.119.2]) by smtp.cs.ucla.edu (Postfix) with ESMTPSA id 50913A60001; Thu, 5 Jul 2012 17:08:53 -0700 (PDT) User-Agent: Mozilla/5.0 (X11; Linux i686; rv:13.0) Gecko/20120615 Thunderbird/13.0.1 In-Reply-To: <83obnu2e8s.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 131.179.128.62 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.devel:151443 Archived-At: On 07/05/2012 12:34 PM, Eli Zaretskii wrote: > ptrdiff_t hscroll_max = min (MOST_POSITIVE_FIXNUM, PTRDIFF_MAX); > ptrdiff_t new_hscroll = clip_to_bounds (0, hscroll, hscroll_max); > > Won't this do The Wrong Thing when Emacs is configured with wide ints? No, because hscroll_max and new_hscroll cannot exceed PTRDIFF_MAX (the above code guarantees this directly), so their values therefore always fit in ptrdiff_t range even when EMACS_INT is wider than ptrdiff_t. Similarly, buffer and string positions cannot exceed BUF_BYTES_MAX and STRING_BYTES_MAX, which in turn cannot exceed PTRDIFF_MAX; so ptrdiff_t always suffices for them too. If we change hscroll values from ptrdiff_t to int, as I think Dmitry is proposing, the above code should be changed to use int and INT_MAX instead of ptrdiff_t and PTRDIFF_MAX.