🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.emacs.bug
Article #98520

narrowing bug

#98520
From: Jamie Zawinski
Date: Tue, 16 Jul 1991 03:30
38 lines
2145 bytes
There's a well known bug (to VM users at least) in emacs 18.5[5-7] and 19,
which goes something like this: you are in a mail buffer, and reply to the
current message.  You are now in a sendmail buffer; if you switch back to the
mail buffer, it is narrowed to the wrong place, beginning somewhere near the
beginning of the buffer (often in the middle of a line).

This is due to a subtle bug in save_restriction_restore() in editfns.c:
This function does this as its last action:

  /* If point is outside the new visible range, move it inside. */
  SET_BUF_PT (buf, in_accessible_range (BUF_PT (buf)));

But the problem is, the function in_accessible_range() looks at the narrowing
region of current_buffer instead of the buffer whose restriction is being
restored!  This means that if the current buffer is not the same on exit from
save-restriction as on the way in, all bets are off.

I believe the correct fix is for in_accessible_range() to take an additional
argument, the buffer in question.  There are only two calls to it.

static int
in_accessible_range (buf, loc)
     struct buffer *buf;
     int loc;
{
  if (loc < BUF_BEGV (buf))
    return BUF_BEGV (buf);

  if (loc > BUF_ZV (buf))
    return BUF_ZV (buf);

  return loc;
}

Note that this bug could cause emacs to crash, because it can allow point to
exceed point-max.

	-- Jamie
Technical Details
Message-ID: <JWZ.91Jul15233009@thalidomide.lucid.com>
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!spool.mu.edu!snorkelwacker.mit.edu!ai-lab!ai.mit.edu!gnulists

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f6829,97f993b5976887a3,start
X-Google-Attributes: gidf6829,public
X-Google-Thread: fb2f1,97f993b5976887a3,start
X-Google-Attributes: gidfb2f1,public
X-Google-ArrivalTime: 1991-07-15 20:30:09 PST
Path: arc1-ca.pugleaf.net!gmdzi!unido!mcsun!uunet!spool.mu.edu!snorkelwacker.mit.edu!ai-lab!ai.mit.edu!gnulists
From: jwz%karoshi@lucid.com (Jamie Zawinski)
Newsgroups: gnu.emacs.bug,gnu.emacs.vm.bug
Subject: narrowing bug
Message-ID: <JWZ.91Jul15233009@thalidomide.lucid.com>
Date: 16 Jul 91 03:30:09 GMT
Followup-To: gnu.emacs.bug
Organization: Lucid, Inc., Menlo Park, CA
Lines: 38
Approved: info-gnu@prep.ai.mit.edu
X-Windows: The Cutting Edge of Obsolescence.
Apparently-To: gnu-emacs-bug@Decwrl.dec.com