components/tcsh/patches/001.gethost.c.patch
changeset 1096 d79c1a1cf681
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/components/tcsh/patches/001.gethost.c.patch	Sat Jan 05 09:19:55 2013 -0800
@@ -0,0 +1,91 @@
+RCS file: /p/tcsh/cvsroot/tcsh/gethost.c,v
+retrieving revision 1.15
+diff -u -u -r1.15 gethost.c
+--- tcsh-6.18.01/gethost.c.orig	15 Jan 2012 17:14:54 -0000	1.15
++++ tcsh-6.18.01/gethost.c	4 Jan 2013 22:20:19 -0000
[email protected]@ -150,11 +150,17 @@
+ 	char *r;
+ 
+ 	if (len == 0)
+-		len = strlen(b);
+-	l = strlen(a) + len + 1;
++		len = strlen(b) + 1;
++	if (a)
++	    l = strlen(a) + len;
++	else
++	    l = len;
+ 	if ((r = malloc(l)) == NULL)
+ 		abort();
+-	snprintf(r, l, "%s%.*s", a, (int)len, b);
++	if (a)
++	    snprintf(r, l, "%s%.*s", a, (int)len, b);
++	else
++	    snprintf(r, l, "%.*s", (int)len, b);
+ 	return r;
+ }
+ 
[email protected]@ -171,13 +177,15 @@
+ 		return defs;
+ 
+ 	free(buf);
+-	buf = strdup("("); /* ) */
++	buf = NULL;
+ 	for (ptr = defs; (bptr = strstr(ptr, def)) != NULL; ptr = eptr + 1) {
+ 		if (ptr != bptr)
+ 			buf = cat(buf, ptr, bptr - ptr);
++		buf = cat(buf, "(", 0); /* ) */
+ 		if ((eptr = strchr(ptr + sizeof(def) - 1, ')')) == NULL) {
+ 			(void) fprintf(stderr, "%s: missing close paren `%s'\n",
+ 			    pname, defs);
++			free(buf);
+ 			return defs;
+ 		}
+ 		buf = cat(buf, bptr, eptr - bptr + 1);
[email protected]@ -186,26 +194,29 @@
+ 		if (len < 1) {
+ 			(void) fprintf(stderr, "%s: empty define `%s'\n",
+ 			    pname, defs);
++			free(buf);
+ 			return defs;
+ 		}
+ 		if (*name != '_') {
+ 			char *undername = malloc(len + 10);
+-			buf = cat(buf, " || defined(", 0);
++			if (undername == NULL)
++				abort();
++			buf = cat(buf, ") || defined(", 0);
+ 			snprintf(undername, len + 10, "__%.*s__)", (int)len,
+ 			    name);
+ 			buf = cat(buf, undername, len + 5);
+-			buf = cat(buf, " || defined(", 0);
++			buf = cat(buf, ") || defined(", 0);
+ 			snprintf(undername, len + 10, "__%.*s)", (int)len,
+ 			    name);
+ 			buf = cat(buf, undername, len + 3);
+ 		}
++		buf = cat(buf, "))", 0);
+ 	}
+ 	if (!eptr) {
+ 	    (void) fprintf(stderr, "%s: invalid input `%s'\n", pname, defs);
+ 	    return defs;
+         }
+ 	buf = cat(buf, eptr + 1, 0);
+-	buf = cat(buf, ")", 0);
+ 	return buf;
+ }
+ 
+
+RCS file: /p/tcsh/cvsroot/tcsh/gethost.c,v
+retrieving revision 1.16
+diff -u -r1.16 gethost.c
+--- tcsh-6.18.01/gethost.c.orig	4 Jan 2013 22:20:37 -0000	1.16
++++ tcsh-6.18.01/gethost.c	5 Jan 2013 01:22:56 -0000
[email protected]@ -180,7 +180,7 @@
+ 	buf = NULL;
+ 	for (ptr = defs; (bptr = strstr(ptr, def)) != NULL; ptr = eptr + 1) {
+ 		if (ptr != bptr)
+-			buf = cat(buf, ptr, bptr - ptr);
++			buf = cat(buf, ptr, bptr - ptr + 1);
+ 		buf = cat(buf, "(", 0); /* ) */
+ 		if ((eptr = strchr(ptr + sizeof(def) - 1, ')')) == NULL) {
+ 			(void) fprintf(stderr, "%s: missing close paren `%s'\n",