[PATCH 1/2] ntdll/tests: Use the available ARRAY_SIZE() macro

Michael Stefaniuc mstefani at winehq.org
Thu Jun 21 16:06:11 CDT 2018


Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>
---
 dlls/ntdll/tests/directory.c  |  4 ++--
 dlls/ntdll/tests/exception.c  | 16 +++++++---------
 dlls/ntdll/tests/file.c       |  4 ++--
 dlls/ntdll/tests/info.c       |  2 +-
 dlls/ntdll/tests/om.c         |  6 +++---
 dlls/ntdll/tests/pipe.c       |  4 ++--
 dlls/ntdll/tests/rtl.c        |  6 +++---
 dlls/ntdll/tests/rtlstr.c     | 10 +++++-----
 dlls/ntdll/tests/string.c     |  2 +-
 dlls/ntdll/tests/threadpool.c | 14 +++++++-------
 10 files changed, 33 insertions(+), 35 deletions(-)

diff --git a/dlls/ntdll/tests/directory.c b/dlls/ntdll/tests/directory.c
index f8f27f9d77..2c6170b8b4 100644
--- a/dlls/ntdll/tests/directory.c
+++ b/dlls/ntdll/tests/directory.c
@@ -74,8 +74,8 @@ static struct testfile_s {
     { 0, 0, FILE_ATTRIBUTE_DIRECTORY, {'.'},                  ". directory" },
     { 0, 0, FILE_ATTRIBUTE_DIRECTORY, {'.','.'},              ".. directory" }
 };
-static const int test_dir_count = sizeof(testfiles) / sizeof(testfiles[0]);
-static const int max_test_dir_size = sizeof(testfiles) / sizeof(testfiles[0]) + 5;  /* size of above plus some for .. etc */
+static const int test_dir_count = ARRAY_SIZE(testfiles);
+static const int max_test_dir_size = ARRAY_SIZE(testfiles) + 5;  /* size of above plus some for .. etc */
 
 static const WCHAR dummyW[] = {'d','u','m','m','y',0};
 static const WCHAR dotW[] = {'.',0};
diff --git a/dlls/ntdll/tests/exception.c b/dlls/ntdll/tests/exception.c
index e30cd593d7..5998f54b04 100644
--- a/dlls/ntdll/tests/exception.c
+++ b/dlls/ntdll/tests/exception.c
@@ -643,7 +643,7 @@ static void test_prot_fault(void)
 {
     unsigned int i;
 
-    for (i = 0; i < sizeof(exceptions)/sizeof(exceptions[0]); i++)
+    for (i = 0; i < ARRAY_SIZE(exceptions); i++)
     {
         if (is_wow64 && exceptions[i].wow64_broken && !strcmp( winetest_platform, "windows" ))
         {
@@ -1734,7 +1734,7 @@ static void call_virtual_unwind( int testnum, const struct unwind_test *test )
 
         for (j = 0; j < 16; j++)
         {
-            static const UINT nb_regs = sizeof(test->results[i].regs) / sizeof(test->results[i].regs[0]);
+            static const UINT nb_regs = ARRAY_SIZE(test->results[i].regs);
 
             for (k = 0; k < nb_regs; k++)
             {
@@ -1888,14 +1888,12 @@ static void test_virtual_unwind(void)
 
     static const struct unwind_test tests[] =
     {
-        { function_0, sizeof(function_0), unwind_info_0,
-          results_0, sizeof(results_0)/sizeof(results_0[0]) },
-        { function_1, sizeof(function_1), unwind_info_1,
-          results_1, sizeof(results_1)/sizeof(results_1[0]) }
+        { function_0, sizeof(function_0), unwind_info_0, results_0, ARRAY_SIZE(results_0) },
+        { function_1, sizeof(function_1), unwind_info_1, results_1, ARRAY_SIZE(results_1) }
     };
     unsigned int i;
 
-    for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
+    for (i = 0; i < ARRAY_SIZE(tests); i++)
         call_virtual_unwind( i, &tests[i] );
 }
 
@@ -2429,7 +2427,7 @@ static void test_prot_fault(void)
 {
     unsigned int i;
 
-    for (i = 0; i < sizeof(exceptions)/sizeof(exceptions[0]); i++)
+    for (i = 0; i < ARRAY_SIZE(exceptions); i++)
     {
         got_exception = 0;
         run_exception_test(handler, &exceptions[i], &exceptions[i].code,
@@ -2567,7 +2565,7 @@ static void test_debug_registers(void)
     HANDLE thread;
     int i;
 
-    for (i = 0; i < sizeof(tests)/sizeof(tests[0]); i++)
+    for (i = 0; i < ARRAY_SIZE(tests); i++)
     {
         memset(&ctx, 0, sizeof(ctx));
         ctx.ContextFlags = CONTEXT_DEBUG_REGISTERS;
diff --git a/dlls/ntdll/tests/file.c b/dlls/ntdll/tests/file.c
index f88d16b449..d9d029b7f3 100644
--- a/dlls/ntdll/tests/file.c
+++ b/dlls/ntdll/tests/file.c
@@ -563,7 +563,7 @@ static void delete_file_test(void)
 	ok(0, "couldn't get temp dir\n");
 	return;
     }
-    if (ret + sizeof(testdirW)/sizeof(WCHAR)-1 + sizeof(subdirW)/sizeof(WCHAR)-1 >= MAX_PATH)
+    if (ret + ARRAY_SIZE(testdirW)-1 + ARRAY_SIZE(subdirW)-1 >= MAX_PATH)
     {
 	ok(0, "MAX_PATH exceeded in constructing paths\n");
 	return;
@@ -3379,7 +3379,7 @@ static void test_NtCreateFile(void)
     attr.SecurityDescriptor = NULL;
     attr.SecurityQualityOfService = NULL;
 
-    for (i = 0; i < sizeof(td)/sizeof(td[0]); i++)
+    for (i = 0; i < ARRAY_SIZE(td); i++)
     {
         status = pNtCreateFile(&handle, GENERIC_READ, &attr, &io, NULL,
                                td[i].attrib_in, FILE_SHARE_READ|FILE_SHARE_WRITE,
diff --git a/dlls/ntdll/tests/info.c b/dlls/ntdll/tests/info.c
index 6c93c3cd58..4a2d9e6933 100644
--- a/dlls/ntdll/tests/info.c
+++ b/dlls/ntdll/tests/info.c
@@ -1613,7 +1613,7 @@ static void test_query_process_debug_flags(int argc, char **argv)
     ok(!status, "NtQueryInformationProcess failed, status %#x.\n", status);
     ok(debug_flags == TRUE, "Expected flag TRUE, got %x.\n", debug_flags);
 
-    for (i = 0; i < sizeof(test_flags)/sizeof(test_flags[0]); i++)
+    for (i = 0; i < ARRAY_SIZE(test_flags); i++)
     {
         DWORD expected_flags = !(test_flags[i] & DEBUG_ONLY_THIS_PROCESS);
         sprintf(cmdline, "%s %s %s", argv[0], argv[1], "debuggee");
diff --git a/dlls/ntdll/tests/om.c b/dlls/ntdll/tests/om.c
index 43c5ee46d7..52b4a83968 100644
--- a/dlls/ntdll/tests/om.c
+++ b/dlls/ntdll/tests/om.c
@@ -650,7 +650,7 @@ static void test_name_limits(void)
 
     /* named pipes */
     memcpy( str.Buffer, pipeW, sizeof(pipeW) );
-    for (i = 0; i < 65536 / sizeof(WCHAR); i++) str.Buffer[i + sizeof(pipeW)/sizeof(WCHAR)] = 'a';
+    for (i = 0; i < 65536 / sizeof(WCHAR); i++) str.Buffer[i + ARRAY_SIZE(pipeW)] = 'a';
     str.Length = 0;
     attr.RootDirectory = 0;
     attr.Attributes = OBJ_CASE_INSENSITIVE;
@@ -703,7 +703,7 @@ static void test_name_limits(void)
 
     /* mailslots */
     memcpy( str.Buffer, mailslotW, sizeof(mailslotW) );
-    for (i = 0; i < 65536 / sizeof(WCHAR); i++) str.Buffer[i + sizeof(mailslotW)/sizeof(WCHAR)] = 'a';
+    for (i = 0; i < 65536 / sizeof(WCHAR); i++) str.Buffer[i + ARRAY_SIZE(mailslotW)] = 'a';
     str.Length = 0;
     status = pNtCreateMailslotFile( &ret, GENERIC_ALL, &attr, &iosb, 0, 0, 0, NULL );
     ok( status == STATUS_OBJECT_PATH_SYNTAX_BAD, "%u: NtCreateMailslotFile failed %x\n", str.Length, status );
@@ -744,7 +744,7 @@ static void test_name_limits(void)
 
     /* registry keys */
     memcpy( str.Buffer, registryW, sizeof(registryW) );
-    for (i = 0; i < 65536 / sizeof(WCHAR); i++) str.Buffer[i + sizeof(registryW)/sizeof(WCHAR)] = 'a';
+    for (i = 0; i < 65536 / sizeof(WCHAR); i++) str.Buffer[i + ARRAY_SIZE(registryW)] = 'a';
     str.Length = 0;
     status = pNtCreateKey( &ret, GENERIC_ALL, &attr, 0, NULL, 0, NULL );
     todo_wine
diff --git a/dlls/ntdll/tests/pipe.c b/dlls/ntdll/tests/pipe.c
index 2978274715..c8e6809423 100644
--- a/dlls/ntdll/tests/pipe.c
+++ b/dlls/ntdll/tests/pipe.c
@@ -230,8 +230,8 @@ static void test_create(void)
     static const DWORD sharing[] =    { FILE_SHARE_READ, FILE_SHARE_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE };
     static const DWORD pipe_config[]= {               1,                0,                                  2 };
 
-    for (j = 0; j < sizeof(sharing) / sizeof(DWORD); j++) {
-        for (k = 0; k < sizeof(access) / sizeof(DWORD); k++) {
+    for (j = 0; j < ARRAY_SIZE(sharing); j++) {
+        for (k = 0; k < ARRAY_SIZE(access); k++) {
             HANDLE hclient;
             BOOL should_succeed = TRUE;
 
diff --git a/dlls/ntdll/tests/rtl.c b/dlls/ntdll/tests/rtl.c
index 2e3a7de75d..db3dc9ff4e 100644
--- a/dlls/ntdll/tests/rtl.c
+++ b/dlls/ntdll/tests/rtl.c
@@ -680,7 +680,7 @@ static void test_RtlRandom(void)
     }
 
     seed = 0;
-    for (i = 0; i < sizeof(res) / sizeof(res[0]); i++)
+    for (i = 0; i < ARRAY_SIZE(res); i++)
     {
         res[i] = pRtlRandom(&seed);
         ok(seed != res[i], "%i: seed is same as res %x\n", i, seed);
@@ -1226,7 +1226,7 @@ static void test_RtlIpv4StringToAddress(void)
         { "::1",             STATUS_INVALID_PARAMETER,  0, { -1 } },
         { ":1",              STATUS_INVALID_PARAMETER,  0, { -1 } },
     };
-    const int testcount = sizeof(tests) / sizeof(tests[0]);
+    const int testcount = ARRAY_SIZE(tests);
     int i;
 
     if (!pRtlIpv4StringToAddressA)
@@ -1787,7 +1787,7 @@ static void test_RtlDecompressBuffer(void)
     ok(final_size == 0xdeadbeef, "got wrong final_size %u\n", final_size);
 
     /* regular tests for RtlDecompressBuffer */
-    for (i = 0; i < sizeof(test_lznt) / sizeof(test_lznt[0]); i++)
+    for (i = 0; i < ARRAY_SIZE(test_lznt); i++)
     {
         trace("Running test %d (compressed_size=%u, uncompressed_size=%u, status=0x%08x)\n",
               i, test_lznt[i].compressed_size, test_lznt[i].uncompressed_size, test_lznt[i].status);
diff --git a/dlls/ntdll/tests/rtlstr.c b/dlls/ntdll/tests/rtlstr.c
index 7f889dfa0d..53cc185939 100644
--- a/dlls/ntdll/tests/rtlstr.c
+++ b/dlls/ntdll/tests/rtlstr.c
@@ -1769,7 +1769,7 @@ static void test_RtlIsTextUnicode(void)
 
     be_unicode = HeapAlloc(GetProcessHeap(), 0, sizeof(unicode) + sizeof(WCHAR));
     be_unicode[0] = 0xfffe;
-    for (i = 0; i < sizeof(unicode)/sizeof(unicode[0]); i++)
+    for (i = 0; i < ARRAY_SIZE(unicode); i++)
     {
         be_unicode[i + 1] = (unicode[i] >> 8) | ((unicode[i] & 0xff) << 8);
     }
@@ -1791,7 +1791,7 @@ static void test_RtlIsTextUnicode(void)
     be_unicode_no_controls = HeapAlloc(GetProcessHeap(), 0, sizeof(unicode) + sizeof(WCHAR));
     ok(be_unicode_no_controls != NULL, "Expected HeapAlloc to succeed.\n");
     be_unicode_no_controls[0] = 0xfffe;
-    for (i = 0; i < sizeof(unicode_no_controls)/sizeof(unicode_no_controls[0]); i++)
+    for (i = 0; i < ARRAY_SIZE(unicode_no_controls); i++)
         be_unicode_no_controls[i + 1] = (unicode_no_controls[i] >> 8) | ((unicode_no_controls[i] & 0xff) << 8);
 
 
@@ -2093,7 +2093,7 @@ static void test_RtlUnicodeToUTF8N(void)
     const WCHAR special_string[] = { 'X',0x80,0xd800,0 };
     const unsigned char special_expected[] = { 'X',0xc2,0x80,0xef,0xbf,0xbd,0 };
     unsigned int input_len;
-    const unsigned int test_count = sizeof(unicode_to_utf8) / sizeof(unicode_to_utf8[0]);
+    const unsigned int test_count = ARRAY_SIZE(unicode_to_utf8);
     unsigned int i;
 
     if (!pRtlUnicodeToUTF8N)
@@ -2374,7 +2374,7 @@ static void unicode_expect_(const WCHAR *out_string, ULONG buflen, ULONG out_cha
             ok_(__FILE__, line)(buffer[i] == out_string[i],
                                 "buffer[%d] = 0x%x, expected 0x%x\n",
                                 i, buffer[i], out_string[i]);
-        for (; i < sizeof(buffer) / sizeof(WCHAR); i++)
+        for (; i < ARRAY_SIZE(buffer); i++)
             ok_(__FILE__, line)(buffer[i] == 0x5555,
                                 "buffer[%d] = 0x%x, expected 0x5555\n",
                                 i, buffer[i]);
@@ -2396,7 +2396,7 @@ static void test_RtlUTF8ToUnicodeN(void)
     const char special_string[] = { 'X',0xc2,0x80,0xF0,0x90,0x80,0x80,0 };
     const WCHAR special_expected[] = { 'X',0x80,0xd800,0xdc00,0 };
     unsigned int input_len;
-    const unsigned int test_count = sizeof(utf8_to_unicode) / sizeof(utf8_to_unicode[0]);
+    const unsigned int test_count = ARRAY_SIZE(utf8_to_unicode);
     unsigned int i;
 
     if (!pRtlUTF8ToUnicodeN)
diff --git a/dlls/ntdll/tests/string.c b/dlls/ntdll/tests/string.c
index 8fca5d46d5..407bc0ffec 100644
--- a/dlls/ntdll/tests/string.c
+++ b/dlls/ntdll/tests/string.c
@@ -1258,7 +1258,7 @@ static void test_bsearch(void)
     int *x, l, i, j;
 
     /* just try all array sizes */
-    for (j=1;j<sizeof(arr)/sizeof(arr[0]);j++) {
+    for (j=1;j<ARRAY_SIZE(arr);j++) {
         for (i=0;i<j;i++) {
             l = arr[i];
             x = p_bsearch (&l, arr, j, sizeof(arr[0]), intcomparefunc);
diff --git a/dlls/ntdll/tests/threadpool.c b/dlls/ntdll/tests/threadpool.c
index af0b6673d3..3bd2d994ec 100644
--- a/dlls/ntdll/tests/threadpool.c
+++ b/dlls/ntdll/tests/threadpool.c
@@ -1824,7 +1824,7 @@ static void test_tp_multi_wait(void)
     environment.Pool = pool;
 
     /* create semaphores and corresponding wait objects */
-    for (i = 0; i < sizeof(semaphores)/sizeof(semaphores[0]); i++)
+    for (i = 0; i < ARRAY_SIZE(semaphores); i++)
     {
         semaphores[i] = CreateSemaphoreW(NULL, 0, 1, NULL);
         ok(semaphores[i] != NULL, "failed to create semaphore %i\n", i);
@@ -1838,7 +1838,7 @@ static void test_tp_multi_wait(void)
     }
 
     /* release all semaphores and wait for callback */
-    for (i = 0; i < sizeof(semaphores)/sizeof(semaphores[0]); i++)
+    for (i = 0; i < ARRAY_SIZE(semaphores); i++)
     {
         multi_wait_info.result = 0;
         ReleaseSemaphore(semaphores[i], 1, NULL);
@@ -1851,7 +1851,7 @@ static void test_tp_multi_wait(void)
     }
 
     /* repeat the same test in reverse order */
-    for (i = sizeof(semaphores)/sizeof(semaphores[0]) - 1; i >= 0; i--)
+    for (i = ARRAY_SIZE(semaphores) - 1; i >= 0; i--)
     {
         multi_wait_info.result = 0;
         ReleaseSemaphore(semaphores[i], 1, NULL);
@@ -1865,13 +1865,13 @@ static void test_tp_multi_wait(void)
 
     /* test timeout of wait objects */
     multi_wait_info.result = 0;
-    for (i = 0; i < sizeof(semaphores)/sizeof(semaphores[0]); i++)
+    for (i = 0; i < ARRAY_SIZE(semaphores); i++)
     {
         when.QuadPart = (ULONGLONG)50 * -10000;
         pTpSetWait(waits[i], semaphores[i], &when);
     }
 
-    for (i = 0; i < sizeof(semaphores)/sizeof(semaphores[0]); i++)
+    for (i = 0; i < ARRAY_SIZE(semaphores); i++)
     {
         result = WaitForSingleObject(semaphore, 150);
         ok(result == WAIT_OBJECT_0, "WaitForSingleObject returned %u\n", result);
@@ -1880,14 +1880,14 @@ static void test_tp_multi_wait(void)
     ok(multi_wait_info.result >> 16, "expected multi_wait_info.result >> 16 != 0\n");
 
     /* destroy the wait objects and semaphores while waiting */
-    for (i = 0; i < sizeof(semaphores)/sizeof(semaphores[0]); i++)
+    for (i = 0; i < ARRAY_SIZE(semaphores); i++)
     {
         pTpSetWait(waits[i], semaphores[i], NULL);
     }
 
     Sleep(50);
 
-    for (i = 0; i < sizeof(semaphores)/sizeof(semaphores[0]); i++)
+    for (i = 0; i < ARRAY_SIZE(semaphores); i++)
     {
         pTpReleaseWait(waits[i]);
         NtClose(semaphores[i]);
-- 
2.14.4




More information about the wine-devel mailing list