all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Paul Eggert <eggert@cs.ucla.edu>
To: Eli Zaretskii <eliz@gnu.org>, Noam Postavsky <npostavs@gmail.com>
Cc: emacs-devel@gnu.org
Subject: Re: Strange code in emacs.c
Date: Wed, 3 Oct 2018 10:36:35 -0700	[thread overview]
Message-ID: <28cf3cf7-8be2-9f6b-711d-bfbd2b625936@cs.ucla.edu> (raw)
In-Reply-To: <83h8i32ha8.fsf@gnu.org>

Eli Zaretskii wrote:
> We have this in 'main':
> 
>        emacs_re_safe_alloca = max
>          (min (lim - extra, SIZE_MAX) * (min_ratio / ratio),
>           MAX_ALLOCA);
> 
> This always yields MAX_ALLOCA because 'ratio' is always greater than
> 'min_ratio':
> 
>        int min_ratio = 20 * sizeof (char *);
>        int ratio = min_ratio + min_ratio / 3;
> 
> Don't we mean to set emacs_re_safe_alloca like this instead:
> 
>        emacs_re_safe_alloca = min (lim - extra, SIZE_MAX) / ratio;
>        emacs_re_safe_alloca = max (emacs_re_safe_alloca * min_ratio, MAX_ALLOCA);

Yes, that sounds better to me too. Also, that SIZE_MAX should be changed to min 
(SIZE_MAX, PTRDIFF_MAX) to avoid (unlikely) integer-overflow issues.

Should this fix be put into master or into the emacs-26 branch?



  reply	other threads:[~2018-10-03 17:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-03 15:15 Strange code in emacs.c Eli Zaretskii
2018-10-03 17:36 ` Paul Eggert [this message]
2018-10-03 17:42   ` Eli Zaretskii
2018-10-03 18:29     ` Paul Eggert
2018-10-03 22:12 ` Noam Postavsky
2018-10-03 22:59   ` Paul Eggert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=28cf3cf7-8be2-9f6b-711d-bfbd2b625936@cs.ucla.edu \
    --to=eggert@cs.ucla.edu \
    --cc=eliz@gnu.org \
    --cc=emacs-devel@gnu.org \
    --cc=npostavs@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

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

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.