Bug 1000079 - Don't let Windows overwrite length 0 strings. r=bsmedberg

This commit is contained in:
James Kitchener 2014-04-24 01:03:00 +02:00
parent 715b91be72
commit 02f9fb48d5

View File

@ -931,8 +931,8 @@ GetRegWindowsAppDataFolder(bool aLocal, nsAString& _retval)
return NS_ERROR_NOT_AVAILABLE;
}
// |size| includes room for the terminating null character
DWORD resultLen = size / 2 - 1;
// |size| may or may not include room for the terminating null character
DWORD resultLen = size / 2;
_retval.SetLength(resultLen);
nsAString::iterator begin;
@ -951,6 +951,11 @@ GetRegWindowsAppDataFolder(bool aLocal, nsAString& _retval)
return NS_ERROR_NOT_AVAILABLE;
}
if (!_retval.CharAt(resultLen - 1)) {
// It was already null terminated.
_retval.Truncate(resultLen - 1);
}
return NS_OK;
}