Don't crash with a NULL thread name.
authorRyan C. Gordon <icculus@icculus.org>
Tue, 18 Oct 2011 00:34:45 -0400
changeset 60003c980a9f983c
parent 5999 0e3fd8178e1d
child 6014 7a8b72b88d86
Don't crash with a NULL thread name.
src/thread/beos/SDL_systhread.c
src/thread/pthread/SDL_systhread.c
src/thread/windows/SDL_systhread.c
     1.1 --- a/src/thread/beos/SDL_systhread.c	Sun Oct 16 03:27:48 2011 -0400
     1.2 +++ b/src/thread/beos/SDL_systhread.c	Tue Oct 18 00:34:45 2011 -0400
     1.3 @@ -66,8 +66,9 @@
     1.4  SDL_SYS_CreateThread(SDL_Thread * thread, void *args)
     1.5  {
     1.6      /* The docs say the thread name can't be longer than B_OS_NAME_LENGTH. */
     1.7 +    const char *threadname = thread->name ? thread->name : "SDL Thread";
     1.8      char name[B_OS_NAME_LENGTH];
     1.9 -    SDL_snprintf(name, sizeof (name), "%s", thread->name);
    1.10 +    SDL_snprintf(name, sizeof (name), "%s", threadname);
    1.11      name[sizeof (name) - 1] = '\0';
    1.12  
    1.13      /* Create the thread and go! */
     2.1 --- a/src/thread/pthread/SDL_systhread.c	Sun Oct 16 03:27:48 2011 -0400
     2.2 +++ b/src/thread/pthread/SDL_systhread.c	Tue Oct 18 00:34:45 2011 -0400
     2.3 @@ -82,14 +82,16 @@
     2.4      int i;
     2.5      sigset_t mask;
     2.6  
     2.7 +    if (name != NULL) {
     2.8  #if ( (__MACOSX__ && (MAC_OS_X_VERSION_MAX_ALLOWED >= 1060)) || \
     2.9        (__IPHONEOS__ && (__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200)) )
    2.10 -    if (pthread_setname_np != NULL) { pthread_setname_np(name); }
    2.11 +        if (pthread_setname_np != NULL) { pthread_setname_np(name); }
    2.12  #elif HAVE_PTHREAD_SETNAME_NP
    2.13 -    pthread_setname_np(pthread_self(), name);
    2.14 +        pthread_setname_np(pthread_self(), name);
    2.15  #elif HAVE_PTHREAD_SET_NAME_NP
    2.16 -    pthread_set_name_np(pthread_self(), name);
    2.17 +        pthread_set_name_np(pthread_self(), name);
    2.18  #endif
    2.19 +    }
    2.20  
    2.21      /* Mask asynchronous signals for this thread */
    2.22      sigemptyset(&mask);
     3.1 --- a/src/thread/windows/SDL_systhread.c	Sun Oct 16 03:27:48 2011 -0400
     3.2 +++ b/src/thread/windows/SDL_systhread.c	Tue Oct 18 00:34:45 2011 -0400
     3.3 @@ -161,25 +161,27 @@
     3.4  void
     3.5  SDL_SYS_SetupThread(const char *name)
     3.6  {
     3.7 -#if 0  /* !!! FIXME: __except needs C runtime, which we don't link against. */
     3.8 -#ifdef _MSC_VER  /* !!! FIXME: can we do SEH on other compilers yet? */
     3.9 -    /* This magic tells the debugger to name a thread if it's listening. */
    3.10 -    THREADNAME_INFO inf;
    3.11 -    inf.dwType = 0x1000;
    3.12 -    inf.szName = name;
    3.13 -    inf.dwThreadID = (DWORD) -1;
    3.14 -    inf.dwFlags = 0;
    3.15 +    if (name != NULL) {
    3.16 +        #if 0  /* !!! FIXME: __except needs C runtime, which we don't link against. */
    3.17 +        #ifdef _MSC_VER  /* !!! FIXME: can we do SEH on other compilers yet? */
    3.18 +        /* This magic tells the debugger to name a thread if it's listening. */
    3.19 +        THREADNAME_INFO inf;
    3.20 +        inf.dwType = 0x1000;
    3.21 +        inf.szName = name;
    3.22 +        inf.dwThreadID = (DWORD) -1;
    3.23 +        inf.dwFlags = 0;
    3.24  
    3.25 -    __try
    3.26 -    {
    3.27 -        RaiseException(0x406D1388, 0, sizeof(inf)/sizeof(DWORD), (DWORD*)&inf);
    3.28 +        __try
    3.29 +        {
    3.30 +            RaiseException(0x406D1388, 0, sizeof(inf)/sizeof(DWORD), (DWORD*)&inf);
    3.31 +        }
    3.32 +        __except(EXCEPTION_CONTINUE_EXECUTION)
    3.33 +        {
    3.34 +            /* The program itself should ignore this bogus exception. */
    3.35 +        }
    3.36 +        #endif
    3.37 +        #endif
    3.38      }
    3.39 -    __except(EXCEPTION_CONTINUE_EXECUTION)
    3.40 -    {
    3.41 -        /* The program itself should ignore this bogus exception. */
    3.42 -    }
    3.43 -#endif
    3.44 -#endif
    3.45  }
    3.46  
    3.47  SDL_threadID