diff options
Diffstat (limited to 'src/dutil/eseutil.cpp')
-rw-r--r-- | src/dutil/eseutil.cpp | 31 |
1 files changed, 24 insertions, 7 deletions
diff --git a/src/dutil/eseutil.cpp b/src/dutil/eseutil.cpp index d2bd7dc5..b9455d4b 100644 --- a/src/dutil/eseutil.cpp +++ b/src/dutil/eseutil.cpp | |||
@@ -312,12 +312,14 @@ HRESULT AllocIndexCreateStruct( | |||
312 | EseExitOnNull(*ppjicIndexCreate, hr, E_OUTOFMEMORY, "Failed to allocate index create structure for database"); | 312 | EseExitOnNull(*ppjicIndexCreate, hr, E_OUTOFMEMORY, "Failed to allocate index create structure for database"); |
313 | 313 | ||
314 | // Record the size including both null terminators - the struct requires this | 314 | // Record the size including both null terminators - the struct requires this |
315 | DWORD dwSize = 0; | 315 | size_t cchSize = 0; |
316 | dwSize = lstrlen(pszMultiSzKeys) + 1; // add 1 to include null character at the end | 316 | hr = ::StringCchLengthA(pszMultiSzKeys, STRSAFE_MAX_LENGTH, &cchSize); |
317 | EseExitOnFailure(hr, "Failed to get size of keys string"); | 317 | EseExitOnRootFailure(hr, "Failed to get size of keys string"); |
318 | |||
319 | ++cchSize; // add 1 to include null character at the end | ||
318 | 320 | ||
319 | // At this point convert all question marks to null characters | 321 | // At this point convert all question marks to null characters |
320 | for (i = 0; i < dwSize; ++i) | 322 | for (i = 0; i < cchSize; ++i) |
321 | { | 323 | { |
322 | if ('?' == pszMultiSzKeys[i]) | 324 | if ('?' == pszMultiSzKeys[i]) |
323 | { | 325 | { |
@@ -328,7 +330,7 @@ HRESULT AllocIndexCreateStruct( | |||
328 | (*ppjicIndexCreate)->cbStruct = sizeof(JET_INDEXCREATE); | 330 | (*ppjicIndexCreate)->cbStruct = sizeof(JET_INDEXCREATE); |
329 | (*ppjicIndexCreate)->szIndexName = pszIndexName; | 331 | (*ppjicIndexCreate)->szIndexName = pszIndexName; |
330 | (*ppjicIndexCreate)->szKey = pszMultiSzKeys; | 332 | (*ppjicIndexCreate)->szKey = pszMultiSzKeys; |
331 | (*ppjicIndexCreate)->cbKey = dwSize; | 333 | (*ppjicIndexCreate)->cbKey = (DWORD)cchSize; |
332 | (*ppjicIndexCreate)->grbit = JET_bitIndexUnique | JET_bitIndexPrimary; | 334 | (*ppjicIndexCreate)->grbit = JET_bitIndexUnique | JET_bitIndexPrimary; |
333 | (*ppjicIndexCreate)->ulDensity = 80; | 335 | (*ppjicIndexCreate)->ulDensity = 80; |
334 | (*ppjicIndexCreate)->lcid = 1033; | 336 | (*ppjicIndexCreate)->lcid = 1033; |
@@ -884,7 +886,16 @@ HRESULT DAPI EseSetColumnString( | |||
884 | { | 886 | { |
885 | HRESULT hr = S_OK; | 887 | HRESULT hr = S_OK; |
886 | JET_ERR jEr = JET_errSuccess; | 888 | JET_ERR jEr = JET_errSuccess; |
887 | ULONG cbValueSize = static_cast<ULONG>((wcslen(pwzValue) + 1) * sizeof(WCHAR)); // add 1 for null character, then multiply by size of WCHAR to get bytes | 889 | size_t cchValue = 0; |
890 | ULONG cbValueSize = 0; | ||
891 | |||
892 | if (pwzValue) | ||
893 | { | ||
894 | hr = ::StringCchLengthW(pwzValue, STRSAFE_MAX_LENGTH, &cchValue); | ||
895 | EseExitOnRootFailure(hr, "Failed to get string length: %ls", pwzValue); | ||
896 | } | ||
897 | |||
898 | cbValueSize = static_cast<ULONG>((cchValue + 1) * sizeof(WCHAR)); // add 1 for null character, then multiply by size of WCHAR to get bytes | ||
888 | 899 | ||
889 | jEr = JetSetColumn(jsSession, tsTable.jtTable, tsTable.pcsColumns[dwColumn].jcColumn, pwzValue, cbValueSize, 0, NULL); | 900 | jEr = JetSetColumn(jsSession, tsTable.jtTable, tsTable.pcsColumns[dwColumn].jcColumn, pwzValue, cbValueSize, 0, NULL); |
890 | ExitOnJetFailure(jEr, hr, "Failed to set string value into column of database: %ls", pwzValue); | 901 | ExitOnJetFailure(jEr, hr, "Failed to set string value into column of database: %ls", pwzValue); |
@@ -1196,11 +1207,17 @@ HRESULT DAPI EseSetQueryColumnString( | |||
1196 | { | 1207 | { |
1197 | HRESULT hr = S_OK; | 1208 | HRESULT hr = S_OK; |
1198 | DWORD dwStringSize = 0; | 1209 | DWORD dwStringSize = 0; |
1210 | size_t cchString = 0; | ||
1199 | ESE_QUERY *peqHandle = static_cast<ESE_QUERY *>(eqhHandle); | 1211 | ESE_QUERY *peqHandle = static_cast<ESE_QUERY *>(eqhHandle); |
1200 | JET_GRBIT jGrb = 0; | 1212 | JET_GRBIT jGrb = 0; |
1201 | 1213 | ||
1202 | dwStringSize = sizeof(WCHAR) * (lstrlenW(pszString) + 1); // Add 1 for null terminator | 1214 | if (pszString) |
1215 | { | ||
1216 | hr = ::StringCchLengthW(pszString, STRSAFE_MAX_LENGTH, &cchString); | ||
1217 | EseExitOnRootFailure(hr, "Failed to get size of column string"); | ||
1218 | } | ||
1203 | 1219 | ||
1220 | dwStringSize = static_cast<DWORD>(sizeof(WCHAR) * (cchString + 1)); // Add 1 for null terminator | ||
1204 | 1221 | ||
1205 | if (fFinal) | 1222 | if (fFinal) |
1206 | { | 1223 | { |