From: "carlo.bramix@libero.it" Subject: [shlwapi] Path: Fix to PathRemoveExtension() Message-Id: <6547004.3550421334008553830.JavaMail.defaultUser@defaultHost> Date: Mon, 9 Apr 2012 23:55:53 +0200 (CEST) FROM BUG #29099: I tried to do some debugging on this bug and I discovered that PathRemoveExtension() crashes on Windows too if a constant string like "labview. txt"is given as parameter, but it does not if the parameter is just "labview": still constant but without dot and extension. The implementation of PathRemoveExtensionA/W in the source of WINE is using PathFindExtensionA/W for finding the extension to be removed; according to MSDN: http://msdn.microsoft.com/en-us/library/windows/desktop/bb773587%28v=vs.85%29. aspx "Returns the address of the "." that precedes the extension within pszPath if an extension is found, or the address of the terminating null character otherwise." So, the only logical explanation I can think on this behavior is that the function does not write the NUL character if it is already existing at the given position. This condition makes lucky working the function, but the reason why LabView is feeding a constant string is a bit unknown to me... Sincerely, Carlo Bramini. PS: I clicked the wrong button and previous email was started with missing the object. Sorry, please excuse me. diff --git a/dlls/shlwapi/path.c b/dlls/shlwapi/path.c index 92a830b..98ac7d9 100644 --- a/dlls/shlwapi/path.c +++ b/dlls/shlwapi/path.c @@ -760,6 +760,10 @@ void WINAPI PathRemoveArgsW(LPWSTR lpszPath) * PARAMS * lpszPath [I/O] Path to remove the extension from * + * NOTES + * The NUL terminator must be written only if extension exists + * and if the pointed character is not already NUL. + * * RETURNS * Nothing. */ @@ -770,7 +774,8 @@ void WINAPI PathRemoveExtensionA(LPSTR lpszPath) if (lpszPath) { lpszPath = PathFindExtensionA(lpszPath); - *lpszPath = '\0'; + if (lpszPath && *lpszPath != '\0') + *lpszPath = '\0'; } } @@ -786,7 +791,8 @@ void WINAPI PathRemoveExtensionW(LPWSTR lpszPath) if (lpszPath) { lpszPath = PathFindExtensionW(lpszPath); - *lpszPath = '\0'; + if (lpszPath && *lpszPath != '\0') + *lpszPath = '\0'; } }