components/tcsh/patches/001.gethost.c.patch
changeset 1096 d79c1a1cf681
equal deleted inserted replaced
1095:e720196b46b2 1096:d79c1a1cf681
       
     1 RCS file: /p/tcsh/cvsroot/tcsh/gethost.c,v
       
     2 retrieving revision 1.15
       
     3 diff -u -u -r1.15 gethost.c
       
     4 --- tcsh-6.18.01/gethost.c.orig	15 Jan 2012 17:14:54 -0000	1.15
       
     5 +++ tcsh-6.18.01/gethost.c	4 Jan 2013 22:20:19 -0000
       
     6 @@ -150,11 +150,17 @@
       
     7  	char *r;
       
     8  
       
     9  	if (len == 0)
       
    10 -		len = strlen(b);
       
    11 -	l = strlen(a) + len + 1;
       
    12 +		len = strlen(b) + 1;
       
    13 +	if (a)
       
    14 +	    l = strlen(a) + len;
       
    15 +	else
       
    16 +	    l = len;
       
    17  	if ((r = malloc(l)) == NULL)
       
    18  		abort();
       
    19 -	snprintf(r, l, "%s%.*s", a, (int)len, b);
       
    20 +	if (a)
       
    21 +	    snprintf(r, l, "%s%.*s", a, (int)len, b);
       
    22 +	else
       
    23 +	    snprintf(r, l, "%.*s", (int)len, b);
       
    24  	return r;
       
    25  }
       
    26  
       
    27 @@ -171,13 +177,15 @@
       
    28  		return defs;
       
    29  
       
    30  	free(buf);
       
    31 -	buf = strdup("("); /* ) */
       
    32 +	buf = NULL;
       
    33  	for (ptr = defs; (bptr = strstr(ptr, def)) != NULL; ptr = eptr + 1) {
       
    34  		if (ptr != bptr)
       
    35  			buf = cat(buf, ptr, bptr - ptr);
       
    36 +		buf = cat(buf, "(", 0); /* ) */
       
    37  		if ((eptr = strchr(ptr + sizeof(def) - 1, ')')) == NULL) {
       
    38  			(void) fprintf(stderr, "%s: missing close paren `%s'\n",
       
    39  			    pname, defs);
       
    40 +			free(buf);
       
    41  			return defs;
       
    42  		}
       
    43  		buf = cat(buf, bptr, eptr - bptr + 1);
       
    44 @@ -186,26 +194,29 @@
       
    45  		if (len < 1) {
       
    46  			(void) fprintf(stderr, "%s: empty define `%s'\n",
       
    47  			    pname, defs);
       
    48 +			free(buf);
       
    49  			return defs;
       
    50  		}
       
    51  		if (*name != '_') {
       
    52  			char *undername = malloc(len + 10);
       
    53 -			buf = cat(buf, " || defined(", 0);
       
    54 +			if (undername == NULL)
       
    55 +				abort();
       
    56 +			buf = cat(buf, ") || defined(", 0);
       
    57  			snprintf(undername, len + 10, "__%.*s__)", (int)len,
       
    58  			    name);
       
    59  			buf = cat(buf, undername, len + 5);
       
    60 -			buf = cat(buf, " || defined(", 0);
       
    61 +			buf = cat(buf, ") || defined(", 0);
       
    62  			snprintf(undername, len + 10, "__%.*s)", (int)len,
       
    63  			    name);
       
    64  			buf = cat(buf, undername, len + 3);
       
    65  		}
       
    66 +		buf = cat(buf, "))", 0);
       
    67  	}
       
    68  	if (!eptr) {
       
    69  	    (void) fprintf(stderr, "%s: invalid input `%s'\n", pname, defs);
       
    70  	    return defs;
       
    71          }
       
    72  	buf = cat(buf, eptr + 1, 0);
       
    73 -	buf = cat(buf, ")", 0);
       
    74  	return buf;
       
    75  }
       
    76  
       
    77 
       
    78 RCS file: /p/tcsh/cvsroot/tcsh/gethost.c,v
       
    79 retrieving revision 1.16
       
    80 diff -u -r1.16 gethost.c
       
    81 --- tcsh-6.18.01/gethost.c.orig	4 Jan 2013 22:20:37 -0000	1.16
       
    82 +++ tcsh-6.18.01/gethost.c	5 Jan 2013 01:22:56 -0000
       
    83 @@ -180,7 +180,7 @@
       
    84  	buf = NULL;
       
    85  	for (ptr = defs; (bptr = strstr(ptr, def)) != NULL; ptr = eptr + 1) {
       
    86  		if (ptr != bptr)
       
    87 -			buf = cat(buf, ptr, bptr - ptr);
       
    88 +			buf = cat(buf, ptr, bptr - ptr + 1);
       
    89  		buf = cat(buf, "(", 0); /* ) */
       
    90  		if ((eptr = strchr(ptr + sizeof(def) - 1, ')')) == NULL) {
       
    91  			(void) fprintf(stderr, "%s: missing close paren `%s'\n",