git: 8df6682efe16 - main - editors/mg: Update 20241008 => 20260519

From: Yusuf Yaman <nxjoseph_at_FreeBSD.org>
Date: Wed, 17 Jun 2026 13:53:24 UTC
The branch main has been updated by nxjoseph:

URL: https://cgit.FreeBSD.org/ports/commit/?id=8df6682efe16041a4e30a75727802ec979a9b78b

commit 8df6682efe16041a4e30a75727802ec979a9b78b
Author:     Mark Willson <cdr.nil@gmail.com>
AuthorDate: 2026-05-21 10:04:04 +0000
Commit:     Yusuf Yaman <nxjoseph@FreeBSD.org>
CommitDate: 2026-06-17 13:53:03 +0000

    editors/mg: Update 20241008 => 20260519
    
    Changelog:
    * file.c: improve the "No changes need to be saved" check
    * fileio.c, funmap.c, echo.c: handle strdup failure
    * re_search.c: fix regex-replace infinite loop issues
    * word.c: rework grabword() a bit; plug a memory leak
    * interpreter.c: fix two memory leaks
    * dired.c: improve externs for KEYMAPE()
    * mg.1: fix typo
    https://cvsweb.openbsd.org/src/usr.bin/mg/
    
    PR:             295474
    MFH:            2026Q2
    Approved by:    osa, vvd (Mentors, implicit)
---
 editors/mg/Makefile                 |  3 ++-
 editors/mg/distinfo                 |  6 +++---
 editors/mg/files/patch-Makefile     | 18 ++++++++++++++----
 editors/mg/files/patch-fileio.c     |  4 ++--
 editors/mg/files/patch-re__search.c | 33 +++++++++++++++++++++++++++++++++
 editors/mg/files/patch-re_search.c  | 15 ---------------
 editors/mg/files/patch-version.c    | 11 +++++++----
 editors/mg/files/patch-word.c       | 17 +++++++++++++++++
 8 files changed, 78 insertions(+), 29 deletions(-)

diff --git a/editors/mg/Makefile b/editors/mg/Makefile
index 8b34f3985b7d..d9991f00f550 100644
--- a/editors/mg/Makefile
+++ b/editors/mg/Makefile
@@ -1,5 +1,5 @@
 PORTNAME=	mg
-DISTVERSION=	20241008
+DISTVERSION=	20260519
 PORTEPOCH=	1
 CATEGORIES=	editors
 MASTER_SITES=	https://hydrus.org.uk/downloads/
@@ -28,6 +28,7 @@ OPTIONS_DEFINE=	DOCS
 .endif
 
 MAKE_ARGS+=	BINDIR=${PREFIX}/bin \
+		DISTVERSION=${DISTVERSION} \
 		MANDIR=${PREFIX}/share/man/man \
 		NCURSESINC=${NCURSESINC} \
 		NCURSESLIB=${NCURSESLIB}
diff --git a/editors/mg/distinfo b/editors/mg/distinfo
index cc1097eb12b9..84da42a83a77 100644
--- a/editors/mg/distinfo
+++ b/editors/mg/distinfo
@@ -1,3 +1,3 @@
-TIMESTAMP = 1728587995
-SHA256 (mg-20241008.tar.gz) = 56a1caf883ab968dd4c6a2d13cf56232d392e834b9cfaf2dd2f4d3b6cf26db75
-SIZE (mg-20241008.tar.gz) = 154865
+TIMESTAMP = 1779272952
+SHA256 (mg-20260519.tar.gz) = adf632f9e5009a29114122266b8c78350692e31a162476584c2ee043568e5da7
+SIZE (mg-20260519.tar.gz) = 154901
diff --git a/editors/mg/files/patch-Makefile b/editors/mg/files/patch-Makefile
index 2b36c667ada6..7c31d30d9149 100644
--- a/editors/mg/files/patch-Makefile
+++ b/editors/mg/files/patch-Makefile
@@ -1,12 +1,22 @@
---- Makefile.orig	2023-10-22 13:42:02 UTC
+--- Makefile.orig	2019-07-18 05:57:48 UTC
 +++ Makefile
-@@ -29,9 +29,4 @@ SRCS+=	cmode.c cscope.c dired.c grep.c interpreter.c t
+@@ -11,7 +11,7 @@ DPADD+=	${LIBCURSES} ${LIBUTIL}
+ #	STARTUPFILE	-- look for and handle initialization file.
+ #	MGLOG		-- debug mg internals to a log file.
  #
- #SRCS+=	log.c
+-CFLAGS+=-Wall -DREGEX
++CFLAGS+=-Wall -DREGEX -DVERSION=\"${DISTVERSION}\"
  
+ SRCS=	autoexec.c basic.c bell.c buffer.c cinfo.c dir.c display.c \
+	echo.c extend.c file.c fileio.c funmap.c help.c kbd.c keymap.c \
+@@ -28,10 +28,5 @@ SRCS+=	cmode.c cscope.c dired.c grep.c interpreter.c t
+ # -DMGLOG source file.
+ #
+ #SRCS+=	log.c
+-
 -afterinstall:
 -	${INSTALL} -d -o root -g wheel ${DESTDIR}${DOCDIR}/mg
 -	${INSTALL} ${INSTALL_COPY} -o ${DOCOWN} -g ${DOCGRP} -m ${DOCMODE} \
 -	    ${.CURDIR}/tutorial ${DESTDIR}${DOCDIR}/mg
--
+
  .include <bsd.prog.mk>
diff --git a/editors/mg/files/patch-fileio.c b/editors/mg/files/patch-fileio.c
index 94d8a5ba0ac5..f04cab0d1a27 100644
--- a/editors/mg/files/patch-fileio.c
+++ b/editors/mg/files/patch-fileio.c
@@ -1,4 +1,4 @@
---- fileio.c.orig	2023-10-22 13:42:02 UTC
+--- fileio.c.orig	2026-05-19 14:58:49 UTC
 +++ fileio.c
 @@ -22,6 +22,7 @@
  #include <stdlib.h>
@@ -8,7 +8,7 @@
  
  #include "def.h"
  #include "kbd.h"
-@@ -705,7 +706,7 @@ expandtilde(const char *fn)
+@@ -703,7 +704,7 @@ expandtilde(const char *fn)
  	struct passwd	*pw;
  	struct stat	 statbuf;
  	const char	*cp;
diff --git a/editors/mg/files/patch-re__search.c b/editors/mg/files/patch-re__search.c
new file mode 100644
index 000000000000..fe4b9cc34d43
--- /dev/null
+++ b/editors/mg/files/patch-re__search.c
@@ -0,0 +1,33 @@
+--- re_search.c.orig	2026-05-20 10:30:42 UTC
++++ re_search.c
+@@ -146,6 +146,10 @@ re_queryrepl(int f, int n)
+		return (ABORT);
+	ewprintf("Query replacing %s with %s:", re_pat, news);
+
++	/* If dot on empty line, suppress line forward in re_forwsrch */
++	if (curwp->w_doto == 0 && curwp->w_dotp->l_used == 0)
++		curwp->w_doto = -1;
++
+	/*
+	 * Search forward repeatedly, checking each time whether to insert
+	 * or not.  The "!" case makes the check always true, so it gets put
+@@ -222,6 +226,9 @@ re_repl(int f, int n)
+	    EFNUL | EFNEW | EFCR, re_pat) == NULL)
+                 return (ABORT);
+
++	/* If dot on empty line, suppress line forward in re_forwsrch */
++	if (curwp->w_doto == 0 && curwp->w_dotp->l_used == 0)
++		curwp->w_doto = -1;
+	while (re_forwsrch() == TRUE) {
+		plen = regex_match[0].rm_eo - regex_match[0].rm_so;
+		if (re_doreplace((RSIZE)plen, news) == FALSE)
+@@ -353,6 +360,9 @@ re_forwsrch(void)
+			tdotline++;
+			tbo = 0;
+		}
++	if (tbo < 0)
++		/* line forward was suppressed */
++		tbo = 0;
+	/*
+	 * Note this loop does not process the last line, but this editor
+	 * always makes the last line empty so this is good.
diff --git a/editors/mg/files/patch-re_search.c b/editors/mg/files/patch-re_search.c
deleted file mode 100644
index a37c830b014a..000000000000
--- a/editors/mg/files/patch-re_search.c
+++ /dev/null
@@ -1,15 +0,0 @@
---- re_search.c.orig	2024-04-06 09:29:51 UTC
-+++ re_search.c
-@@ -342,10 +342,9 @@ re_forwsrch(void)
- 	if (tbo == clp->l_used)
- 		/*
- 		 * Don't start matching past end of line -- must move to
--		 * beginning of next line, unless line is empty or at
--		 * end of file.
-+		 * beginning of next line, unless at end of file.
- 		 */
--		if (clp != curbp->b_headp && llength(clp) != 0) {
-+		if (clp != curbp->b_headp) {
- 			clp = lforw(clp);
- 			tdotline++;
- 			tbo = 0;
diff --git a/editors/mg/files/patch-version.c b/editors/mg/files/patch-version.c
index 9c4d4ca3136d..a17922d7eac1 100644
--- a/editors/mg/files/patch-version.c
+++ b/editors/mg/files/patch-version.c
@@ -1,11 +1,14 @@
---- version.c.orig	2024-10-10 16:12:07 UTC
+--- version.c.orig	2023-03-08 04:43:11 UTC
 +++ version.c
-@@ -13,7 +13,7 @@
+@@ -13,7 +13,11 @@
  
  #include "def.h"
  
--const char	version[] = "Mg 2a";
-+const char	version[] = "Mg 2a (20241008)";
++#ifdef VERSION
++const char	version[] = "Mg 2a (" VERSION ")";
++#else
+ const char	version[] = "Mg 2a";
++#endif
  
  /*
   * Display the version. All this does
diff --git a/editors/mg/files/patch-word.c b/editors/mg/files/patch-word.c
new file mode 100644
index 000000000000..6853441519c7
--- /dev/null
+++ b/editors/mg/files/patch-word.c
@@ -0,0 +1,17 @@
+--- word.c.orig	2026-05-20 15:03:11 UTC
++++ word.c
+@@ -209,12 +209,13 @@ grabword(char **word)
+
+	while (inword() == TRUE) {
+		if (cap == 0 || len == cap - 1) {
+-			t = recallocarray(*word, cap, cap + 8, 1);
++			t = realloc(*word, cap + 8);
+			if (t == NULL) {
+				free(*word);
+				*word = NULL;
+				return (errno);
+			}
++			memset(t + cap, 0, 8);
+			cap += 8;
+			*word = t;
+		}