[libsoup] [SoupURI] further fixes to CRLF-stripping



commit 78f5290eec0c12bacef6eb2f9ec28d7f519ae566
Author: Dan Winship <danw gnome org>
Date:   Sat Feb 20 12:44:44 2010 -0500

    [SoupURI] further fixes to CRLF-stripping
    
    The original code mistakenly assumed that strcpy() can take
    overlapping arguments, but that's not guaranteed. Rewrite to do a
    single pass over the string rather than potentially multiple
    strcpy/memmoves.
    
    Fixes "make check" on x86_64.

 libsoup/soup-uri.c |   11 ++++++++---
 1 files changed, 8 insertions(+), 3 deletions(-)
---
diff --git a/libsoup/soup-uri.c b/libsoup/soup-uri.c
index 77a0653..0e3795d 100644
--- a/libsoup/soup-uri.c
+++ b/libsoup/soup-uri.c
@@ -157,10 +157,15 @@ soup_uri_new_with_base (SoupURI *base, const char *uri_string)
 
 	len = strcspn (uri_string, "\t\n\r");
 	if (uri_string[len]) {
-		char *clean = g_strdup (uri_string), *bad;
+		char *clean = g_malloc (strlen (uri_string + 1)), *d;
+		const char *s;
+
+		for (s = uri_string, d = clean; *s; s++) {
+			if (*s != '\t' && *s != '\n' && *s != '\r')
+				*d++ = *s;
+		}
+		*d = '\0';
 
-		while ((bad = strpbrk (clean, "\t\n\r")))
-			strcpy (bad, bad + 1);
 		uri = soup_uri_new_with_base (base, clean);
 		g_free (clean);
 		return uri;



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