On Sat, 15 Nov 2014, Kamil Rytarowski wrote:
> I'm attaching two enhancements against mg(1):
>
> 0001-Include-limits.h-for-INT_MIN-and-INT_MAX.patch
> 0002-Comparison-of-array-bp-b_fname-not-equal-to-a-null-p.patch
The latter patch was committed *months* ago. Please verify you're working
from a current tree! (That probably also explains a rejected chunk in one
of your other diffs that I had to handle manually...)
For the former, I think the diff I correct, but doesn't go far enough.
The reason <limits.h> isn't needed on OpenBSD is that our <sys/param.h> is
pulling in the requisite #defines...but mg doesn't have a good reason for
needing <sys/param.h>! So here's a slightly bigger diff that eliminates
that by switching from MAXPATHLEN to PATH_MAX and expanding the one use of
MAX().
oks?
Index: basic.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/basic.c,v
retrieving revision 1.42
diff -u -p -r1.42 basic.c
--- basic.c 20 Mar 2014 07:47:29 -0000 1.42
+++ basic.c 16 Nov 2014 01:20:18 -0000
@@ -14,6 +14,7 @@
#include "def.h"
#include <ctype.h>
+#include <limits.h>
/*
* Go to beginning of line.
Index: cscope.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/cscope.c,v
retrieving revision 1.7
diff -u -p -r1.7 cscope.c
--- cscope.c 16 Nov 2014 00:59:25 -0000 1.7
+++ cscope.c 16 Nov 2014 01:20:18 -0000
@@ -13,6 +13,7 @@
#include <ctype.h>
#include <fcntl.h>
#include <fnmatch.h>
+#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
Index: dired.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/dired.c,v
retrieving revision 1.67
diff -u -p -r1.67 dired.c
--- dired.c 3 Apr 2014 20:17:12 -0000 1.67
+++ dired.c 16 Nov 2014 01:20:18 -0000
@@ -17,6 +17,7 @@
#include <sys/wait.h>
#include <ctype.h>
+#include <limits.h>
#include <signal.h>
#include <fcntl.h>
#include <err.h>
@@ -496,7 +497,7 @@ reaper(int signo __attribute__((unused))
int
d_shell_command(int f, int n)
{
- char command[512], fname[MAXPATHLEN], *bufp;
+ char command[512], fname[PATH_MAX], *bufp;
struct buffer *bp;
struct mgwin *wp;
char sname[NFILEN];
Index: echo.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/echo.c,v
retrieving revision 1.56
diff -u -p -r1.56 echo.c
--- echo.c 20 Mar 2014 07:47:29 -0000 1.56
+++ echo.c 16 Nov 2014 01:20:19 -0000
@@ -711,7 +711,7 @@ complt_list(int flags, char *buf, int cp
* Now do the display. Objects are written into linebuf until
* it fills, and then put into the help buffer.
*/
- linesize = MAX(ncol, maxwidth) + 1;
+ linesize = (ncol > maxwidth ? ncol : maxwidth) + 1;
if ((linebuf = malloc(linesize)) == NULL) {
free_file_list(wholelist);
return (FALSE);
Index: extend.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/extend.c,v
retrieving revision 1.56
diff -u -p -r1.56 extend.c
--- extend.c 16 Nov 2014 00:59:25 -0000 1.56
+++ extend.c 16 Nov 2014 01:20:19 -0000
@@ -12,6 +12,7 @@
#include <sys/types.h>
#include <ctype.h>
+#include <limits.h>
#include "macro.h"
Index: fileio.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/fileio.c,v
retrieving revision 1.97
diff -u -p -r1.97 fileio.c
--- fileio.c 20 Mar 2014 07:47:29 -0000 1.97
+++ fileio.c 16 Nov 2014 01:20:19 -0000
@@ -289,7 +289,7 @@ fbackupfile(const char *fn)
char *
adjustname(const char *fn, int slashslash)
{
- static char fnb[MAXPATHLEN];
+ static char fnb[PATH_MAX];
const char *cp, *ep = NULL;
char *path;
Index: grep.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/grep.c,v
retrieving revision 1.41
diff -u -p -r1.41 grep.c
--- grep.c 16 Nov 2014 00:59:25 -0000 1.41
+++ grep.c 16 Nov 2014 01:20:19 -0000
@@ -9,6 +9,7 @@
#include <sys/types.h>
#include <ctype.h>
#include <libgen.h>
+#include <limits.h>
#include <time.h>
int globalwd = FALSE;
Index: line.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/line.c,v
retrieving revision 1.53
diff -u -p -r1.53 line.c
--- line.c 20 Mar 2014 07:47:29 -0000 1.53
+++ line.c 16 Nov 2014 01:20:19 -0000
@@ -19,6 +19,7 @@
#include "def.h"
+#include <limits.h>
#include <stdlib.h>
#include <string.h>
Index: main.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/main.c,v
retrieving revision 1.73
diff -u -p -r1.73 main.c
--- main.c 13 Nov 2014 21:36:23 -0000 1.73
+++ main.c 16 Nov 2014 01:20:19 -0000
@@ -12,6 +12,7 @@
#include "macro.h"
#include <err.h>
+#include <limits.h>
#include <locale.h>
int thisflag; /* flags, this command */
Index: paragraph.c
===================================================================
RCS file: /cvs/src/usr.bin/mg/paragraph.c,v
retrieving revision 1.34
diff -u -p -r1.34 paragraph.c
--- paragraph.c 17 Oct 2014 13:25:13 -0000 1.34
+++ paragraph.c 16 Nov 2014 01:20:19 -0000
@@ -8,6 +8,7 @@
*/
#include <ctype.h>
+#include <limits.h>
#include "def.h"
Index: sysdef.h
===================================================================
RCS file: /cvs/src/usr.bin/mg/sysdef.h,v
retrieving revision 1.18
diff -u -p -r1.18 sysdef.h
--- sysdef.h 16 Nov 2014 01:01:28 -0000 1.18
+++ sysdef.h 16 Nov 2014 01:20:19 -0000
@@ -5,7 +5,7 @@
/*
* POSIX system header file
*/
-#include <sys/param.h>
+#include <sys/types.h>
#include <sys/queue.h>
#include <stdio.h>
#include <unistd.h>