components/tcsh/patches/001.gethost.c.patch
author Mike Sullivan <Mike.Sullivan@Oracle.COM>
Mon, 11 Mar 2013 10:38:09 -0700
branchs11-update
changeset 2520 ceec631e74d1
parent 2494 c2dd5561bf4f
permissions -rw-r--r--
Close of build 10.
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
@@ -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;
 }
 
@@ -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);
@@ -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
@@ -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",