[PATCH] check for overflow in testcase
Marcus Meissner
marcus at jet.franken.de
Tue Feb 5 15:15:23 CST 2008
Hi,
Kinda superflous, but check.
spotted by Coverity (CID 306).
Ciao, Marcus
---
dlls/mlang/tests/mlang.c | 14 +++++++++-----
1 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/dlls/mlang/tests/mlang.c b/dlls/mlang/tests/mlang.c
index c036f7a..aa6c7fb 100644
--- a/dlls/mlang/tests/mlang.c
+++ b/dlls/mlang/tests/mlang.c
@@ -161,8 +161,10 @@ static void test_multibyte_to_unicode_translations(IMultiLanguage2 *iML2)
ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
ok(lenA == lstrlenA(stringA), "expected lenA %u, got %u\n", lstrlenA(stringA), lenA);
ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
- ok(bufA[lenA] != 0, "buf should not be 0 terminated\n");
- bufA[lenA] = 0; /* -1 doesn't include 0 terminator */
+ if (lenA < sizeof(bufA)-1) {
+ ok(bufA[lenA] != 0, "buf should not be 0 terminated\n");
+ bufA[lenA] = 0; /* -1 doesn't include 0 terminator */
+ }
ok(!lstrcmpA(bufA, stringA), "bufA/stringA mismatch\n");
memset(bufA, 'x', sizeof(bufA));
@@ -183,9 +185,11 @@ static void test_multibyte_to_unicode_translations(IMultiLanguage2 *iML2)
ok(ret == S_OK, "IMultiLanguage2_ConvertStringFromUnicode failed: %08x\n", ret);
ok(lenA == lstrlenA(stringA) * (int)sizeof(WCHAR), "wrong lenA %u\n", lenA);
ok(lenW == lstrlenW(stringW), "expected lenW %u, got %u\n", lstrlenW(stringW), lenW);
- ok(bufA[lenA] != 0 && bufA[lenA+1] != 0, "buf should not be 0 terminated\n");
- bufA[lenA] = 0; /* -1 doesn't include 0 terminator */
- bufA[lenA+1] = 0; /* sizeof(WCHAR) */
+ if (lenA < sizeof(bufA)-2) {
+ ok(bufA[lenA] != 0 && bufA[lenA+1] != 0, "buf should not be 0 terminated\n");
+ bufA[lenA] = 0; /* -1 doesn't include 0 terminator */
+ bufA[lenA+1] = 0; /* sizeof(WCHAR) */
+ }
ok(!lstrcmpW((LPCWSTR)bufA, stringW), "bufA/stringW mismatch\n");
memset(bufA, 'x', sizeof(bufA));
--
1.5.2.4
More information about the wine-patches
mailing list