summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorlum <lum@openbsd.org>2016-08-31 12:22:28 +0000
committerlum <lum@openbsd.org>2016-08-31 12:22:28 +0000
commit442062a33776d23ec5fac3e4ec8fc1c13cd64b2a (patch)
treebe5c003bca3fa4fa6783501cce0c0bd8cd5c18ce
parentWe don't need any VMS access tricks. (diff)
downloadwireguard-openbsd-442062a33776d23ec5fac3e4ec8fc1c13cd64b2a.tar.xz
wireguard-openbsd-442062a33776d23ec5fac3e4ec8fc1c13cd64b2a.zip
Fix a bug reported by Han Boetes. Easily reproducible via:
mg c-x b RET c-x k RET mg segvs. Initial diff from Joachim Nilsson. This diff tested by Han and Joachim and ok florian@ jasper@
-rw-r--r--usr.bin/mg/buffer.c31
1 files changed, 14 insertions, 17 deletions
diff --git a/usr.bin/mg/buffer.c b/usr.bin/mg/buffer.c
index ba0aa6bfeed..e518ecfc337 100644
--- a/usr.bin/mg/buffer.c
+++ b/usr.bin/mg/buffer.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: buffer.c,v 1.100 2015/10/10 08:35:26 lum Exp $ */
+/* $OpenBSD: buffer.c,v 1.101 2016/08/31 12:22:28 lum Exp $ */
/* This file is in the public domain. */
@@ -55,12 +55,13 @@ togglereadonly(int f, int n)
int
usebufname(const char *bufp)
{
- struct buffer *bp;
+ struct buffer *bp = NULL;
- if (bufp == NULL)
- return (ABORT);
- if (bufp[0] == '\0' && curbp->b_altb != NULL)
- bp = curbp->b_altb;
+ if (bufp == NULL) {
+ if ((bp = bfind("*scratch*", TRUE)) == NULL)
+ return(FALSE);
+ } else if (bufp[0] == '\0' && curbp->b_altb != NULL)
+ bp = curbp->b_altb;
else if ((bp = bfind(bufp, TRUE)) == NULL)
return (FALSE);
@@ -82,8 +83,7 @@ usebuffer(int f, int n)
char bufn[NBUFN], *bufp;
/* Get buffer to use from user */
- if ((curbp->b_altb == NULL) &&
- ((curbp->b_altb = bfind("*scratch*", TRUE)) == NULL))
+ if (curbp->b_altb == NULL)
bufp = eread("Switch to buffer: ", bufn, NBUFN, EFNEW | EFBUF);
else
bufp = eread("Switch to buffer: (default %s) ", bufn, NBUFN,
@@ -169,15 +169,12 @@ killbuffer(struct buffer *bp)
* buffer. Return if *scratch* is only buffer...
*/
if ((bp1 = bp->b_altb) == NULL) {
- bp1 = (bp == bheadp) ? bp->b_bufp : bheadp;
- if (bp1 == NULL) {
- /* only one buffer. see if it's *scratch* */
- if (bp == bfind("*scratch*", FALSE))
- return (TRUE);
- /* create *scratch* for alternate buffer */
- if ((bp1 = bfind("*scratch*", TRUE)) == NULL)
- return (FALSE);
- }
+ /* only one buffer. see if it's *scratch* */
+ if (bp == bfind("*scratch*", FALSE))
+ return (TRUE);
+ /* create *scratch* for alternate buffer */
+ if ((bp1 = bfind("*scratch*", TRUE)) == NULL)
+ return (FALSE);
}
if ((s = bclear(bp)) != TRUE)
return (s);