Bug 635546 - Calculate the string length correctly for REG_EXPAND_SZ values expanded through nsWindowsRegKey::ReadStringValue; r=bsmedberg,jimm a=blocking-betaN+

The buffer length returned from ExpandEnvironmentStringsW includes the terminatng
null character, so we need to decrement it before setting the string length, as
XPCOM strings need to be stored with correct length information.
This commit is contained in:
Ehsan Akhgari 2011-02-22 11:05:26 -05:00
parent 0312a750a6
commit d9b3b4ace6

View File

@ -337,6 +337,8 @@ nsWindowsRegKey::ReadStringValue(const nsAString &name, nsAString &result)
resultLen = ExpandEnvironmentStringsW(flatSource.get(), NULL, 0);
if (resultLen > 0) {
nsAutoString expandedResult;
// |resultLen| includes the terminating null character
--resultLen;
expandedResult.SetLength(resultLen);
nsAString::iterator begin;
expandedResult.BeginWriting(begin);
@ -345,11 +347,11 @@ nsWindowsRegKey::ReadStringValue(const nsAString &name, nsAString &result)
resultLen = ExpandEnvironmentStringsW(flatSource.get(),
begin.get(),
resultLen);
resultLen + 1);
if (resultLen <= 0) {
rv = ERROR_UNKNOWN_FEATURE;
result.Truncate();
} else if (resultLen > 0) {
} else {
rv = ERROR_SUCCESS;
result = expandedResult;
}