Skip to content

Commit

Permalink
Fix a bug that the string without null terminator
Browse files Browse the repository at this point in the history
  • Loading branch information
songbaoming committed Dec 14, 2016
1 parent f7b210d commit 5f5fd9e
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions IncBuildVer/VerFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,11 @@ LPTSTR CVerFile::FileContentToUnicode(LPCSTR lpszSrc, LONGLONG llLen)
else {
DWORD dwLen = MultiByteToWideChar(m_dwCode, 0, lpszSrc, llLen, nullptr, 0);
if (dwLen) {
pContent = new TCHAR[dwLen];
if (pContent)
pContent = new TCHAR[dwLen + 1];
if (pContent){
MultiByteToWideChar(m_dwCode, 0, lpszSrc, llLen, pContent, dwLen);
pContent[dwLen] = 0;
}
}
}
return pContent;
Expand Down Expand Up @@ -351,7 +353,7 @@ bool CVerFile::WriteContent(LPCTSTR lpszContent, DWORD dwLen)
auto pBuff = new char[nLen];
if (pBuff) {
WideCharToMultiByte(m_dwCode, 0, lpszContent, dwLen, pBuff, nLen, nullptr, nullptr);
auto bRes = WriteFile(m_hFile, pBuff, nLen - 1, &dwWriten, nullptr);
auto bRes = WriteFile(m_hFile, pBuff, nLen, &dwWriten, nullptr);
delete[] pBuff;
return bRes;
}
Expand Down

0 comments on commit 5f5fd9e

Please sign in to comment.