Commit 20161434 201614344012a58d96a9564308b0201351b8b36f by Sergey Poznyakoff

(get_pathname): Make sure no extra slash is inserted.

1 parent 112667db
...@@ -446,10 +446,17 @@ get_pathname (const char *dirname, const char *basename) ...@@ -446,10 +446,17 @@ get_pathname (const char *dirname, const char *basename)
446 /* Relative. */ 446 /* Relative. */
447 else 447 else
448 { 448 {
449 size_t len = strlen (basename); 449 size_t baselen = strlen (basename);
450 pathname = calloc (strlen (dirname) + len + 2, sizeof (char)); 450 size_t dirlen = strlen (dirname);
451 while (dirlen > 0 && dirname[dirlen-1] == '/')
452 dirlen--;
453 pathname = calloc (dirname + baselen + 2, sizeof (char));
451 if (pathname) 454 if (pathname)
452 sprintf (pathname, "%s/%s", dirname, basename); 455 {
456 memcpy (pathname, dirname, dirlen);
457 pathname[dirlen] = '/';
458 strcpy (pathname + dirlen + 1, basename);
459 }
453 } 460 }
454 return pathname; 461 return pathname;
455 } 462 }
......