Skip to content

Commit bb4bfaf

Browse files
Fix SalGetFileAttributes and SalMoveFile to correctly handle paths with trailing spaces or dots
1 parent d762dbe commit bb4bfaf

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/salamdr5.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1228,12 +1228,14 @@ BOOL SalMoveFile(const char* srcName, const char* destName)
12281228
// if name ends with space/dot, we must append '\\', otherwise MoveFile
12291229
// will trim spaces/dots and work with different name
12301230
char srcNameCopy[3 * MAX_PATH];
1231-
MakeCopyWithBackslashIfNeeded(srcName, srcNameCopy);
1231+
const char* srcNameToUse = srcName;
1232+
MakeCopyWithBackslashIfNeeded(srcNameToUse, srcNameCopy);
12321233
char destNameCopy[3 * MAX_PATH];
1233-
MakeCopyWithBackslashIfNeeded(destName, destNameCopy);
1234+
const char* destNameToUse = destName;
1235+
MakeCopyWithBackslashIfNeeded(destNameToUse, destNameCopy);
12341236

1235-
CStrP srcNameW(ConvertAllocUtf8ToWide(srcName, -1));
1236-
CStrP destNameW(ConvertAllocUtf8ToWide(destName, -1));
1237+
CStrP srcNameW(ConvertAllocUtf8ToWide(srcNameToUse, -1));
1238+
CStrP destNameW(ConvertAllocUtf8ToWide(destNameToUse, -1));
12371239
if (srcNameW == NULL || destNameW == NULL)
12381240
{
12391241
SetLastError(ERROR_NO_UNICODE_TRANSLATION);
@@ -1512,9 +1514,10 @@ DWORD SalGetFileAttributes(const char* fileName)
15121514
// but still better than getting attributes of different file/directory (for "c:\\file.txt "
15131515
// works with name "c:\\file.txt")
15141516
char fileNameCopy[3 * MAX_PATH];
1515-
MakeCopyWithBackslashIfNeeded(fileName, fileNameCopy);
1517+
const char* fileNameToUse = fileName;
1518+
MakeCopyWithBackslashIfNeeded(fileNameToUse, fileNameCopy);
15161519

1517-
CStrP fileNameW(ConvertAllocUtf8ToWide(fileName, -1));
1520+
CStrP fileNameW(ConvertAllocUtf8ToWide(fileNameToUse, -1));
15181521
if (fileNameW == NULL)
15191522
{
15201523
SetLastError(ERROR_NO_UNICODE_TRANSLATION);

0 commit comments

Comments
 (0)