msvcrt: fix _makepath() to better match native behaviour

Peter Beutner p.beutner at gmx.net
Tue Jul 31 18:58:04 CDT 2007


Freelancer passes the same buffer as output buffer and
one of the input buffers. Change to implementation to
work correctly in that case. Testcase included.

Fixes bug 8251.
---
 dlls/msvcrt/dir.c       |   24 ++++++++++++------------
 dlls/msvcrt/tests/dir.c |   16 ++++++++++++++++
 2 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/dlls/msvcrt/dir.c b/dlls/msvcrt/dir.c
index 21a3115..d0d7edc 100644
--- a/dlls/msvcrt/dir.c
+++ b/dlls/msvcrt/dir.c
@@ -853,7 +853,7 @@ VOID CDECL _makepath(char * path, const char * drive,
                      const char *directory, const char * filename,
                      const char * extension)
 {
-    char ch;
+    char *p = path;
 
     TRACE("(%s %s %s %s)\n", debugstr_a(drive), debugstr_a(directory),
           debugstr_a(filename), debugstr_a(extension) );
@@ -861,28 +861,28 @@ VOID CDECL _makepath(char * path, const char * drive,
     if ( !path )
         return;
 
-    path[0] = '\0';
     if (drive && drive[0])
     {
-        path[0] = drive[0];
-        path[1] = ':';
-        path[2] = 0;
+        *p++ = drive[0];
+        *p++ = ':';
+        *p = 0;
     }
     if (directory && directory[0])
     {
-        strcat(path, directory);
-        ch = path[strlen(path)-1];
-        if (ch != '/' && ch != '\\')
-            strcat(path,"\\");
+        strcpy(p, directory);
+        p += strlen(directory);
+        if (*(p-1) != '/' && *(p-1) != '\\') {
+            *p++ = '\\';
+        }
     }
     if (filename && filename[0])
     {
-        strcat(path, filename);
+        strcpy(p, filename);
         if (extension && extension[0])
         {
             if ( extension[0] != '.' )
-                strcat(path,".");
-            strcat(path,extension);
+                strcat(p,".");
+            strcat(p,extension);
         }
     }
     TRACE("returning %s\n",path);
diff --git a/dlls/msvcrt/tests/dir.c b/dlls/msvcrt/tests/dir.c
index 009cbdb..6929a76 100644
--- a/dlls/msvcrt/tests/dir.c
+++ b/dlls/msvcrt/tests/dir.c
@@ -31,6 +31,21 @@
 #include <process.h>
 #include <errno.h>
 
+static void test_makepath(void)
+{
+    char buffer[MAX_PATH];
+
+    _makepath(buffer, "C", "\\foo", "dummy", "txt");
+    ok( strcmp(buffer, "C:\\foo\\dummy.txt") == 0, "unexpected result: %s\n", buffer);
+    _makepath(buffer, "C:", "\\foo\\", "dummy", ".txt");
+    ok( strcmp(buffer, "C:\\foo\\dummy.txt") == 0, "unexpected result: %s\n", buffer);
+
+    /* this works with native and e.g. Freelancer depends on it */
+    strcpy(buffer, "foo");
+    _makepath(buffer, NULL, buffer, "dummy.txt", NULL);
+    ok( strcmp(buffer, "foo\\dummy.txt") == 0, "unexpected result: %s\n", buffer);
+}
+
 static void test_fullpath(void)
 {
     char full[MAX_PATH];
@@ -91,4 +106,5 @@ static void test_fullpath(void)
 START_TEST(dir)
 {
     test_fullpath();
+    test_makepath();
 }
-- 
1.5.2




More information about the wine-patches mailing list