[glib] thread: Check sysconf value before using it



commit f7b13e05f9bc5bd2b54f589d16ad580f6d833173
Author: Mattias Ellert <mattias ellert fysast uu se>
Date:   Fri Oct 24 12:29:00 2014 +0000

    thread: Check sysconf value before using it
    
    sysconf() is documented as returning -1 if it can't determine
    a minimum thread stack size. Check for this case before using
    the return value.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=739122

 glib/gthread-posix.c |    4 +++-
 1 files changed, 3 insertions(+), 1 deletions(-)
---
diff --git a/glib/gthread-posix.c b/glib/gthread-posix.c
index ae5d805..bd3c9a1 100644
--- a/glib/gthread-posix.c
+++ b/glib/gthread-posix.c
@@ -1159,7 +1159,9 @@ g_system_thread_new (GThreadFunc   thread_func,
   if (stack_size)
     {
 #ifdef _SC_THREAD_STACK_MIN
-      stack_size = MAX (sysconf (_SC_THREAD_STACK_MIN), stack_size);
+      long min_stack_size = sysconf (_SC_THREAD_STACK_MIN);
+      if (min_stack_size >= 0)
+        stack_size = MAX (min_stack_size, stack_size);
 #endif /* _SC_THREAD_STACK_MIN */
       /* No error check here, because some systems can't do it and
        * we simply don't want threads to fail because of that. */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]