Skip to content

Commit

Permalink
[core] Fix path canonicalization on Windows
Browse files Browse the repository at this point in the history
This fixes a regression from a59f6fd.
  • Loading branch information
eumagga0x2a committed Nov 26, 2022
1 parent e94c731 commit 7588039
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion avidemux_core/ADM_core/src/ADM_folder_win32.cpp
Expand Up @@ -270,14 +270,35 @@ static void simplify_path(char **buf)
\fn ADM_PathCanonize
\brief Canonize the path, returns a copy of the absolute path given as parameter
*/
char *ADM_PathCanonize(const char *tmpname)
char *ADM_PathCanonize(const char *namein)
{
char *out;
char *tmpname = NULL;

if (namein && strlen(namein))
{
tmpname = new char[strlen(namein) + 1];
strcpy(tmpname, namein);
}

// replace forward slashes as passed by Qt with backslashes
if (tmpname)
{
char *slash = strchr(tmpname, '/');
uintptr_t end = (uintptr_t)strchr(tmpname, 0);
while(slash && (uintptr_t)slash < end)
{
*slash = '\\';
slash = strchr(slash, '/');
}
}

if (tmpname && strlen(tmpname) > 1 && (tmpname[0] == '\\' || tmpname[1] == ':')) // already an absolute path?
{
out = new char[strlen(tmpname) + 1];
strcpy(out, tmpname);
delete [] tmpname;
tmpname = NULL;
simplify_path(&out);
return out;
}
Expand Down Expand Up @@ -322,6 +343,13 @@ char *ADM_PathCanonize(const char *tmpname)
strcat(out, "\\");
strcat(out, tmpname);
}

if (tmpname)
{
delete [] tmpname;
tmpname = NULL;
}

delete [] path;
path = NULL;

Expand Down

0 comments on commit 7588039

Please sign in to comment.