看板 DFBSD_submit 關於我們 聯絡資訊
This is a multi-part message in MIME format. --------------070407080405020606070505 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Instead of modifying a const string parameter, we just calculate the length of the string instead of null terminating and using strlen(). Max --------------070407080405020606070505 Content-Type: text/plain; name="patch-6.4" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patch-6.4" --- var_modify.c.orig Sat Nov 27 06:08:10 2004 +++ var_modify.c Sat Nov 27 06:11:39 2004 @@ -70,9 +70,7 @@ if (addSpace) { Buf_AddByte (buf, (Byte)' '); } - *slash = '\0'; - Buf_AddBytes (buf, strlen (word), (Byte *)word); - *slash = '/'; + Buf_AddBytes (buf, slash - word, (Byte *)word); return (TRUE); } else { /* @@ -105,7 +103,7 @@ Boolean VarTail (const char *word, Boolean addSpace, Buffer buf, void *dummy __unused) { - char *slash; + const char *slash; if (addSpace) { Buf_AddByte (buf, (Byte)' '); @@ -113,9 +111,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); } @@ -139,16 +136,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); @@ -180,9 +176,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); } @@ -214,7 +208,7 @@ Buf_AddByte(buf, (Byte)' '); } addSpace = TRUE; - Buf_AddBytes(buf, strlen(word), (Byte *)word); + Buf_AddBytes(buf, strlen(word), word); } return(addSpace); } --------------070407080405020606070505--