summaryrefslogtreecommitdiff
path: root/misc/less/patches/patch-ab
blob: e4c1d7eefae21187dd04700f93491b03fac53fbc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
$NetBSD: patch-ab,v 1.1 2006/09/27 11:28:32 taca Exp $

--- tags.c.orig	2004-02-04 13:52:27.000000000 +0900
+++ tags.c
@@ -498,7 +498,7 @@ findgtag(tag, type)
 #if !HAVE_POPEN
 		return TAG_NOFILE;
 #else
-		char command[512];
+		char *command;
 		char *flag;
 		char *qtag;
 		char *cmd = lgetenv("LESSGLOBALTAGS");
@@ -528,10 +528,13 @@ findgtag(tag, type)
 		qtag = shell_quote(tag);
 		if (qtag == NULL)
 			qtag = tag;
+		command = (char *)ecalloc(strlen(cmd) + strlen(flag) +
+		    strlen(qtag) + 5, sizeof(char));
 		sprintf(command, "%s -x%s %s", cmd, flag, qtag);
 		if (qtag != tag)
 			free(qtag);
 		fp = popen(command, "r");
+		free(command);
 #endif
 	}
 	if (fp != NULL)
@@ -539,6 +542,7 @@ findgtag(tag, type)
 		while (fgets(buf, sizeof(buf), fp))
 		{
 			char *name, *file, *line;
+			size_t len;
 
 			if (sigs)
 			{
@@ -548,8 +552,8 @@ findgtag(tag, type)
 #endif
 				return TAG_INTR;
 			}
-			if (buf[strlen(buf) - 1] == '\n')
-				buf[strlen(buf) - 1] = 0;
+			if ((len = strlen(buf)) && buf[len - 1] == '\n')
+				buf[len - 1] = 0;
 			else
 			{
 				int c;