[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: ptrdiff_t misuse

From: Eli Zaretskii
Subject: Re: ptrdiff_t misuse
Date: Fri, 06 Jul 2012 11:34:37 +0300

> Date: Fri, 06 Jul 2012 00:32:06 -0700
> From: Paul Eggert <address@hidden>
> CC: address@hidden, address@hidden, address@hidden
> On 07/05/2012 11:43 PM, Eli Zaretskii wrote:
> > The value of 'hscroll' comes from Lisp,
> > so it's in the range of an EMACS_INT.
> > Why not treat it as such?
> > 
> > For that matter, why not change 'hscroll' in 'struct window' to
> > EMACS_INT as well?
> I would prefer that, yes.  Although Stefan said last week that
> hscroll should be 'int'
> <http://lists.gnu.org/archive/html/emacs-devel/2012-06/msg00603.html>
> on the grounds that hscroll values greater than INT_MAX don't work
> anyway, perhaps that's moot now that you've fixed those problems with
> large hscroll values.

Stefan, do you object to making hscroll (and other values that come
from Lisp) EMACS_INT?

I think doing so will naturally and easily avoid the messy tests
against max values of several data types where we want to clip values
to some reasonable range.  So I think it will be a net win in code
clarity and maintainability, and will prevent subtle bugs.

> If we change hscroll to EMACS_INT, we should also increase the max
> hscroll value to MOST_POSITIVE_FIXNUM.

It's already that:

     ptrdiff_t hscroll_max = min (MOST_POSITIVE_FIXNUM, PTRDIFF_MAX);
     ptrdiff_t new_hscroll = clip_to_bounds (0, hscroll, hscroll_max);

(Of course, if we declare these variables EMACS_INT, PTRDIFF_MAX will
not be needed anymore.)

Or did you mean something else?

reply via email to

[Prev in Thread] Current Thread [Next in Thread]