Alexandre Julliard : advapi32/tests: Use debug.h functions.

Alexandre Julliard julliard at winehq.org
Tue Dec 17 15:58:19 CST 2019


Module: wine
Branch: master
Commit: 4429b9f803de199c4fb8460049d8296baec5a407
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=4429b9f803de199c4fb8460049d8296baec5a407

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Dec 17 16:00:12 2019 +0100

advapi32/tests: Use debug.h functions.

Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/advapi32/tests/registry.c | 95 ++++--------------------------------------
 dlls/advapi32/tests/security.c | 16 ++-----
 dlls/shell32/tests/shlexec.c   |  4 +-
 3 files changed, 14 insertions(+), 101 deletions(-)

diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c
index 675426d4a9..e4d4893bd4 100644
--- a/dlls/advapi32/tests/registry.c
+++ b/dlls/advapi32/tests/registry.c
@@ -59,88 +59,11 @@ static DWORD (WINAPI *pEnumDynamicTimeZoneInformation)(const DWORD,
 
 static BOOL limited_user;
 
-
-/* Debugging functions from wine/libs/wine/debug.c */
-
-/* allocate some tmp string space */
-/* FIXME: this is not 100% thread-safe */
-static char *get_temp_buffer( int size )
-{
-    static char *list[32];
-    static UINT pos;
-    char *ret;
-    UINT idx;
-
-    idx = ++pos % ARRAY_SIZE(list);
-    if (list[idx])
-        ret = HeapReAlloc( GetProcessHeap(), 0, list[idx], size );
-    else
-        ret = HeapAlloc( GetProcessHeap(), 0, size );
-    if (ret) list[idx] = ret;
-    return ret;
-}
-
-static const char *wine_debugstr_an( const char *str, int n )
-{
-    static const char hex[16] = "0123456789abcdef";
-    char *dst, *res;
-    size_t size;
-
-    if (!((ULONG_PTR)str >> 16))
-    {
-        if (!str) return "(null)";
-        res = get_temp_buffer( 6 );
-        sprintf( res, "#%04x", LOWORD(str) );
-        return res;
-    }
-    if (n == -1) n = strlen(str);
-    if (n < 0) n = 0;
-    size = 10 + min( 300, n * 4 );
-    dst = res = get_temp_buffer( size );
-    *dst++ = '"';
-    while (n-- > 0 && dst <= res + size - 9)
-    {
-        unsigned char c = *str++;
-        switch (c)
-        {
-        case '\n': *dst++ = '\\'; *dst++ = 'n'; break;
-        case '\r': *dst++ = '\\'; *dst++ = 'r'; break;
-        case '\t': *dst++ = '\\'; *dst++ = 't'; break;
-        case '"':  *dst++ = '\\'; *dst++ = '"'; break;
-        case '\\': *dst++ = '\\'; *dst++ = '\\'; break;
-        default:
-            if (c >= ' ' && c <= 126)
-                *dst++ = c;
-            else
-            {
-                *dst++ = '\\';
-                *dst++ = 'x';
-                *dst++ = hex[(c >> 4) & 0x0f];
-                *dst++ = hex[c & 0x0f];
-            }
-        }
-    }
-    *dst++ = '"';
-    if (n > 0)
-    {
-        *dst++ = '.';
-        *dst++ = '.';
-        *dst++ = '.';
-    }
-    *dst++ = 0;
-    return res;
-}
-
 static const char *dbgstr_SYSTEMTIME(const SYSTEMTIME *st)
 {
-    static int index;
-    static char buf[2][64];
-
-    index %= ARRAY_SIZE(buf);
-    sprintf(buf[index], "%02d-%02d-%04d %02d:%02d:%02d.%03d",
-            st->wMonth, st->wDay, st->wYear,
-            st->wHour, st->wMinute, st->wSecond, st->wMilliseconds);
-    return buf[index++];
+    return wine_dbg_sprintf("%02d-%02d-%04d %02d:%02d:%02d.%03d",
+                            st->wMonth, st->wDay, st->wYear,
+                            st->wHour, st->wMinute, st->wSecond, st->wMilliseconds);
 }
 
 #define ADVAPI32_GET_PROC(func) \
@@ -263,8 +186,8 @@ static void _test_hkey_main_Value_A(int line, LPCSTR name, LPCSTR string,
     else
     {
         lok(memcmp(value, string, cbData) == 0, "RegQueryValueExA/2 failed: %s/%d != %s/%d\n",
-           wine_debugstr_an((char*)value, cbData), cbData,
-           wine_debugstr_an(string, full_byte_len), full_byte_len);
+           debugstr_an((char*)value, cbData), cbData,
+           debugstr_an(string, full_byte_len), full_byte_len);
         lok(*(value+cbData) == 0xbd, "RegQueryValueExA/2 overflowed at offset %u: %02x != bd\n", cbData, *(value+cbData));
     }
     HeapFree(GetProcessHeap(), 0, value);
@@ -2089,7 +2012,7 @@ static void test_string_termination(void)
     ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", ret);
     ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
     ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
-       wine_debugstr_an((char*)buffer, outsize), outsize, string);
+       debugstr_an((char*)buffer, outsize), outsize, string);
     ok(buffer[insize] == 0xbd, "buffer overflow at %u %02x\n", insize, buffer[insize]);
 
     /* RegQueryValueExA adds a trailing '\0' if there is room */
@@ -2099,7 +2022,7 @@ static void test_string_termination(void)
     ok(ret == ERROR_SUCCESS, "RegQueryValueExA failed: %d\n", ret);
     ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
     ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
-       wine_debugstr_an((char*)buffer, outsize), outsize, string);
+       debugstr_an((char*)buffer, outsize), outsize, string);
     ok(buffer[insize] == 0, "buffer overflow at %u %02x\n", insize, buffer[insize]);
 
     /* RegEnumValueA may return a string with no trailing '\0' */
@@ -2111,7 +2034,7 @@ static void test_string_termination(void)
     ok(strcmp(name, "stringtest") == 0, "wrong name: %s\n", name);
     ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
     ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
-       wine_debugstr_an((char*)buffer, outsize), outsize, string);
+       debugstr_an((char*)buffer, outsize), outsize, string);
     ok(buffer[insize] == 0xbd, "buffer overflow at %u %02x\n", insize, buffer[insize]);
 
     /* RegEnumValueA adds a trailing '\0' if there is room */
@@ -2123,7 +2046,7 @@ static void test_string_termination(void)
     ok(strcmp(name, "stringtest") == 0, "wrong name: %s\n", name);
     ok(outsize == insize, "wrong size: %u != %u\n", outsize, insize);
     ok(memcmp(buffer, string, outsize) == 0, "bad string: %s/%u != %s\n",
-       wine_debugstr_an((char*)buffer, outsize), outsize, string);
+       debugstr_an((char*)buffer, outsize), outsize, string);
     ok(buffer[insize] == 0, "buffer overflow at %u %02x\n", insize, buffer[insize]);
 
     RegDeleteKeyA(subkey, "");
diff --git a/dlls/advapi32/tests/security.c b/dlls/advapi32/tests/security.c
index bddcdef6bb..8bcd16cb95 100644
--- a/dlls/advapi32/tests/security.c
+++ b/dlls/advapi32/tests/security.c
@@ -140,27 +140,17 @@ static HMODULE hmod;
 static int     myARGC;
 static char**  myARGV;
 
-#define SID_SLOTS 4
-static char debugsid_str[SID_SLOTS][256];
-static int debugsid_index = 0;
 static const char* debugstr_sid(PSID sid)
 {
     LPSTR sidstr;
     DWORD le = GetLastError();
-    char* res = debugsid_str[debugsid_index];
-    debugsid_index = (debugsid_index + 1) % SID_SLOTS;
+    const char *res;
 
     if (!ConvertSidToStringSidA(sid, &sidstr))
-        sprintf(res, "ConvertSidToStringSidA failed le=%u", GetLastError());
-    else if (strlen(sidstr) > sizeof(*debugsid_str) - 1)
-    {
-        memcpy(res, sidstr, sizeof(*debugsid_str) - 4);
-        strcpy(res + sizeof(*debugsid_str) - 4, "...");
-        LocalFree(sidstr);
-    }
+        res = wine_dbg_sprintf("ConvertSidToStringSidA failed le=%u", GetLastError());
     else
     {
-        strcpy(res, sidstr);
+        res = __wine_dbg_strdup(sidstr);
         LocalFree(sidstr);
     }
     /* Restore the last error in case ConvertSidToStringSidA() modified it */
diff --git a/dlls/shell32/tests/shlexec.c b/dlls/shell32/tests/shlexec.c
index 496006985c..12ef18c1d8 100644
--- a/dlls/shell32/tests/shlexec.c
+++ b/dlls/shell32/tests/shlexec.c
@@ -117,7 +117,7 @@ static char* decodeA(const char* str)
     return ptr;
 }
 
-static void WINAPIV WINETEST_PRINTF_ATTR(2,3) childPrintf(HANDLE h, const char* fmt, ...)
+static void WINAPIV __WINE_PRINTF_ATTR(2,3) childPrintf(HANDLE h, const char* fmt, ...)
 {
     __ms_va_list valist;
     char        buffer[1024];
@@ -351,7 +351,7 @@ static void dump_child_(const char* file, int line)
  ***/
 
 static char shell_call[2048];
-static void WINAPIV WINETEST_PRINTF_ATTR(2,3) _okShell(int condition, const char *msg, ...)
+static void WINAPIV __WINE_PRINTF_ATTR(2,3) _okShell(int condition, const char *msg, ...)
 {
     __ms_va_list valist;
     char buffer[2048];




More information about the wine-cvs mailing list