emacs-devel
[Top][All Lists]
Advanced

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

Re: ptrdiff_t misuse [was :Re: (empty)]


From: Paul Eggert
Subject: Re: ptrdiff_t misuse [was :Re: (empty)]
Date: Thu, 05 Jul 2012 17:08:50 -0700
User-agent: Mozilla/5.0 (X11; Linux i686; rv:13.0) Gecko/20120615 Thunderbird/13.0.1

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.



reply via email to

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