unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
* MOST_POSITIVE_FIXNUM and maximum buffer/string size
@ 2011-04-29 11:35 Eli Zaretskii
  2011-04-29 16:28 ` Stefan Monnier
  0 siblings, 1 reply; 2+ messages in thread
From: Eli Zaretskii @ 2011-04-29 11:35 UTC (permalink / raw)
  To: emacs-devel

This came up in the context of bug #8545, see

  http://debbugs.gnu.org/cgi/bugreport.cgi?bug=8545#70

Here's the thing: we currently use MOST_POSITIVE_FIXNUM both as the
maximum value of a Lisp integer, and as a maximum size of buffers and
strings Emacs can handle.  But for a buffer that holds N characters,
buffer positions are numbered 1 to N+1, because the value of point at
EOB is N+1.  If we allow N to be as large as MOST_POSITIVE_FIXNUM, the
value of point at EOB will overflow, at least on the Lisp level, if
not in C.

Unless I'm missing something, this means we need to limit buffer sizes
to MOST_POSITIVE_FIXNUM-1.

A related issue is with strings.  String positions are zero-based, so
there's no problem with overflow there.  But if a string whose length
is MOST_POSITIVE_FIXNUM is inserted into a buffer, we will again have
an overflow.  So should we limit strings to MOST_POSITIVE_FIXNUM-1 as
well?

Admittedly, this issue is of practical importance only for 32-bit
hosts.  However, since a significant effort was invested lately by
several individuals to clean up the mess we had with using incorrect
sizes and limitations of this kind, I think it would be good to clean
up this issue as well.

Comments and opinions are welcome.



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: MOST_POSITIVE_FIXNUM and maximum buffer/string size
  2011-04-29 11:35 MOST_POSITIVE_FIXNUM and maximum buffer/string size Eli Zaretskii
@ 2011-04-29 16:28 ` Stefan Monnier
  0 siblings, 0 replies; 2+ messages in thread
From: Stefan Monnier @ 2011-04-29 16:28 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: emacs-devel

> Unless I'm missing something, this means we need to limit buffer sizes
> to MOST_POSITIVE_FIXNUM-1.

That's right (I wish I could change BEGV to 0, but that would break
a bit too much Elisp code, sadly, tho most of Emacs' own Elisp code is
somewhat clean in this respect).

> A related issue is with strings.  String positions are zero-based, so
> there's no problem with overflow there.  But if a string whose length
> is MOST_POSITIVE_FIXNUM is inserted into a buffer, we will again have
> an overflow.  So should we limit strings to MOST_POSITIVE_FIXNUM-1 as
> well?

I don't think so: when inserting a string, we have to check that we
don't make the buffer too large anyway, so there's no need to do
anything special in this respect.  Of course, we can also limit strings
to MOST_POSITIVE_FIXNUM-1, and I don't think anybody will mind, but it's
not necessary AFAIK.


        Stefan



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-04-29 16:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-04-29 11:35 MOST_POSITIVE_FIXNUM and maximum buffer/string size Eli Zaretskii
2011-04-29 16:28 ` Stefan Monnier

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).