DragonFly BSD
DragonFly submit List (threaded) for 2004-12
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

usr.bin/make Changes to lying const code


From: Max Okumoto <okumoto@xxxxxxxx>
Date: Mon, 13 Dec 2004 13:41:24 -0800

Can people look over this patch to fix code that was
modifying const strings?

Max
Index: var_modify.c
===================================================================
RCS file: /cvs/src/usr.bin/make/var_modify.c,v
retrieving revision 1.4
diff -u -r1.4 var_modify.c
--- var_modify.c	10 Dec 2004 20:34:01 -0000	1.4
+++ var_modify.c	13 Dec 2004 21:36:02 -0000
@@ -73,10 +73,7 @@
 	if (addSpace) {
 	    Buf_AddByte(buf, (Byte)' ');
 	}
-	*slash = '\0';
-	Buf_AddBytes(buf, strlen(word), (Byte *)word);
-	*slash = '/';
-	return (TRUE);
+	Buf_AddBytes(buf, slash - word, (Byte *)word);
     } else {
 	/*
 	 * If no directory part, give . (q.v. the POSIX standard)
@@ -108,7 +105,7 @@
 Boolean
 VarTail(const char *word, Boolean addSpace, Buffer buf, void *dummy __unused)
 {
-    char *slash;
+    const char *slash;
 
     if (addSpace) {
 	Buf_AddByte(buf, (Byte)' ');
@@ -116,9 +113,8 @@
 
     slash = strrchr(word, '/');
     if (slash != NULL) {
-	*slash++ = '\0';
+	slash++;
 	Buf_AddBytes(buf, strlen(slash), (Byte *)slash);
-	slash[-1] = '/';
     } else {
 	Buf_AddBytes(buf, strlen(word), (Byte *)word);
     }
@@ -142,16 +138,15 @@
 Boolean
 VarSuffix(const char *word, Boolean addSpace, Buffer buf, void *dummy __unused)
 {
-    char *dot;
+    const char *dot;
 
     dot = strrchr(word, '.');
     if (dot != NULL) {
 	if (addSpace) {
 	    Buf_AddByte(buf, (Byte)' ');
 	}
-	*dot++ = '\0';
+	dot++;
 	Buf_AddBytes(buf, strlen(dot), (Byte *)dot);
-	dot[-1] = '.';
 	addSpace = TRUE;
     }
     return (addSpace);
@@ -183,9 +178,7 @@
 
     dot = strrchr(word, '.');
     if (dot != NULL) {
-	*dot = '\0';
-	Buf_AddBytes(buf, strlen(word), (Byte *)word);
-	*dot = '.';
+	Buf_AddBytes(buf, dot - word, (Byte *)word);
     } else {
 	Buf_AddBytes(buf, strlen(word),(Byte *)word);
     }
@@ -218,7 +211,7 @@
 	    Buf_AddByte(buf, (Byte)' ');
 	}
 	addSpace = TRUE;
-	Buf_AddBytes(buf, strlen(word), (Byte *)word);
+	Buf_AddBytes(buf, strlen(word), word);
     }
     return (addSpace);
 }


[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]