From 838a1010c29c332212d2fff50235687c6b30657d Mon Sep 17 00:00:00 2001 From: Ron Koenderink Date: Sat, 13 Sep 2008 15:18:29 -0600 Subject: [PATCH] Allow any length thread names for WIN32 Dynamically allocate the string space for thread name in WIN32 (ntthread.c) thread space. This makes the WIN32 more consistent with the other environments. It also addresses WIN32 issue of the print width of 17 being used and only having space for 16 characters in the fixed allocation. --- src/lib/empthread/ntthread.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/lib/empthread/ntthread.c b/src/lib/empthread/ntthread.c index dd57a158..b8d2ab8b 100644 --- a/src/lib/empthread/ntthread.c +++ b/src/lib/empthread/ntthread.c @@ -73,7 +73,7 @@ struct loc_Thread { /* The thread name, passed in at create time. */ - char szName[17]; + char *szName; /* True if this is the main line, and not a real thread. */ BOOL bMainThread; @@ -224,6 +224,8 @@ loc_FreeThreadInfo(empth_t *pThread) if (pThread) { if (pThread->hThreadEvent) CloseHandle(pThread->hThreadEvent); + if (pThread->szName != NULL) + free(pThread->szName); memset(pThread, 0, sizeof(*pThread)); free(pThread); } @@ -403,7 +405,7 @@ empth_init(void **ctx_ptr, int flags) } memset(pThread, 0, sizeof(*pThread)); - strncpy(pThread->szName, "Main", sizeof(pThread->szName) - 1); + pThread->szName = strdup("Main"); pThread->ulThreadID = GetCurrentThreadId(); pThread->bMainThread = TRUE; @@ -446,7 +448,7 @@ empth_create(void (*entry)(void *), int size, int flags, } memset(pThread, 0, sizeof(*pThread)); - strncpy(pThread->szName, name, sizeof(pThread->szName) - 1); + pThread->szName = strdup(name); pThread->pvUserData = ud; pThread->pfnEntry = entry; pThread->bMainThread = FALSE; @@ -502,7 +504,9 @@ empth_name(empth_t *thread) void empth_set_name(empth_t *thread, char *name) { - strncpy(thread->szName, name, sizeof(thread->szName) - 1); + if (thread->szName != NULL) + free(thread->szName); + thread->szName = strdup(name); } /************************