[PATCH 1/2] kernel/tests: Implement safe local strcat function.
Saulius Krasuckas
saulius.krasuckas at ieee.org
Tue Jul 4 04:12:14 CDT 2006
Will be used later too.
---
dlls/kernel/tests/file.c | 30 ++++++++++++++++++++----------
1 files changed, 20 insertions(+), 10 deletions(-)
658e00c3e0820726964e34cf597e612ad512d39c
diff --git a/dlls/kernel/tests/file.c b/dlls/kernel/tests/file.c
index a0e8181..78d6983 100644
--- a/dlls/kernel/tests/file.c
+++ b/dlls/kernel/tests/file.c
@@ -1443,6 +1443,22 @@ static void test_read_write(void)
ok( ret, "DeleteFileA: error %ld\n", GetLastError());
}
+static void safe_strcatA(char *dst, DWORD dst_len, const char *src)
+{
+ UINT length;
+ char *buff;
+
+ length = lstrlenA(dst);
+ length += lstrlenA(src);
+ buff = HeapAlloc(GetProcessHeap(), 0, length + 1);
+
+ lstrcpyA(buff, dst);
+ lstrcatA(buff, src);
+ lstrcpynA(dst, buff, dst_len);
+
+ HeapFree(GetProcessHeap(), 0, buff);
+}
+
static void test_OpenFile(void)
{
HFILE hFile;
@@ -1452,18 +1468,12 @@ static void test_OpenFile(void)
static const char *file = "\\regsvr32.exe";
char buff[MAX_PATH];
- UINT length;
/* Check for existing file */
- length = GetSystemDirectoryA(buff, MAX_PATH);
-
- if ((length + lstrlen(file) < MAX_PATH))
- {
- lstrcatA(buff, file);
-
- hFile = OpenFile(buff, &ofs, OF_EXIST);
- ok( hFile == TRUE, "%s not found : %ld\n", buff, GetLastError());
- }
+ GetSystemDirectoryA(buff, MAX_PATH);
+ safe_strcatA(buff, MAX_PATH, file);
+ hFile = OpenFile(buff, &ofs, OF_EXIST);
+ ok( hFile == TRUE, "%s not found : %ld\n", buff, GetLastError() );
/* Check for nonexistent file */
SetLastError(0xfaceabee);
--
1.3.3
More information about the wine-patches
mailing list