pyRXP: fix x64 bug with help from rxp-1.5 thanks to Roger Whittaker <roger@disruptive.org.uk> & Tim Roberts <timr@probo.com>
authorrgbecker
Wed, 18 May 2011 21:03:10 +0000
changeset 6 b98871fd77e2
parent 5 4022300ebb5e
child 7 555d2cc6278c
pyRXP: fix x64 bug with help from rxp-1.5 thanks to Roger Whittaker <roger@disruptive.org.uk> & Tim Roberts <timr@probo.com>
src/pyRXP.c
src/rxp/url.c
--- a/src/pyRXP.c	Wed Dec 01 13:51:09 2010 +0000
+++ b/src/pyRXP.c	Wed May 18 21:03:10 2011 +0000
@@ -21,7 +21,7 @@
 #include "stdio16.h"
 #include "version.h"
 #include "namespaces.h"
-#define VERSION "1.14"
+#define VERSION "1.15"
 #define MAX_DEPTH 256
 #if PY_VERSION_HEX < 0x02050000
 #	define Py_ssize_t int
--- a/src/rxp/url.c	Wed Dec 01 13:51:09 2010 +0000
+++ b/src/rxp/url.c	Wed May 18 21:03:10 2011 +0000
@@ -77,6 +77,8 @@
 
 static int hexval(int hex);
 
+static char *mystrcpy(char *s1, const char *s2);
+
 /* Mapping of scheme names to opening functions */
 
 struct {
@@ -254,7 +256,8 @@
 
 	    if(j - i == 2 && p[i+1] == '.')
 	    {
-		strcpy(&p[i+1], p[j] ? &p[j+1] : &p[j]);
+		mystrcpy(&p[i+1], p[j] ? &p[j+1] : &p[j]);
+		i = 0;		/* start again from beginning */
 		continue;
 	    }
 
@@ -268,7 +271,7 @@
 	       (p[j+3] == '/' || p[j+3] == '\0') &&
 	       (j - i != 3 || p[i+1] != '.' || p[i+2] != '.'))
 	    {
-		strcpy(&p[i+1], p[j+3] ? &p[j+4] : &p[j+3]);
+		mystrcpy(&p[i+1], p[j+3] ? &p[j+4] : &p[j+3]);
 		i = 0;		/* start again from beginning */
 		continue;
 	    }
@@ -559,6 +562,14 @@
     *scheme = *host = *path = 0;
     *port = -1;
 
+    /* Check for degenerate case */
+    
+    if(url[0] == 0)
+    {
+	*path = strdup8("");
+	return;
+    }
+
     /* Does it start with a scheme? */
     
     for(p = (char *)url; *p; p++)
@@ -634,3 +645,16 @@
 	return hex - 'A' + 10;
     return -1;
 }
+
+/* version of strcpy that works for overlapping strings */
+
+static char *mystrcpy(char *s1, const char *s2)
+{
+    char *t = s1;
+
+    while(*s2)
+	*s1++ = *s2++;
+    *s1 = 0;
+
+    return t;
+}