From adb78bd47184bf028a8a25f030a143b30f9104b3 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Fri, 18 Sep 2020 12:22:47 +0200 Subject: [PATCH] tests: mark static variables in test helpers as thread local We should avoid static variables in general, but for test helpers they are often convenient. Mark them as thread local to make them safer to use. The only downsides may only be some runtime overhead, which is negligible for unit tests. --- shared/nm-utils/nm-test-utils.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/shared/nm-utils/nm-test-utils.h b/shared/nm-utils/nm-test-utils.h index 08ba9166c..446b86b3a 100644 --- a/shared/nm-utils/nm-test-utils.h +++ b/shared/nm-utils/nm-test-utils.h @@ -1356,7 +1356,7 @@ static inline const char * \ nmtst_static_##SIZE##_##NUM (const char *str) \ { \ gsize l; \ - static char buf[SIZE]; \ + static _nm_thread_local char buf[SIZE]; \ \ if (!str) \ return NULL; \ @@ -1378,7 +1378,7 @@ __define_nmtst_static(03, 1024) static inline const char * nmtst_uuid_generate (void) { - static char u[37]; + static _nm_thread_local char u[37]; gs_free char *m = NULL; m = nm_utils_uuid_generate (); @@ -1419,7 +1419,7 @@ nmtst_inet4_from_string (const char *str) static inline const struct in6_addr * nmtst_inet6_from_string (const char *str) { - static struct in6_addr addr; + static _nm_thread_local struct in6_addr addr; int success; if (!str) @@ -1451,7 +1451,7 @@ nmtst_inet_from_string (int addr_family, const char *str) static inline const char * nmtst_inet_to_string (int addr_family, gconstpointer addr) { - static char buf[NM_CONST_MAX (INET6_ADDRSTRLEN, INET_ADDRSTRLEN)]; + static _nm_thread_local char buf[NM_CONST_MAX (INET6_ADDRSTRLEN, INET_ADDRSTRLEN)]; g_assert (NM_IN_SET (addr_family, AF_INET, AF_INET6)); g_assert (addr);