From: Augustin Degomme Date: Wed, 21 Nov 2012 16:23:18 +0000 (+0100) Subject: secure the stack size parameter for thread, X-Git-Tag: v3_9_rc1~91^2~55^2~2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/c49140baf3058c9e38e1c5cc38140d676012ac0a?ds=sidebyside secure the stack size parameter for thread, to avoid some segfaults when the value is not right --- diff --git a/src/xbt/xbt_os_thread.c b/src/xbt/xbt_os_thread.c index d07112d2b7..4b7d8fbcc5 100644 --- a/src/xbt/xbt_os_thread.c +++ b/src/xbt/xbt_os_thread.c @@ -194,8 +194,17 @@ xbt_os_thread_t xbt_os_thread_create(const char *name, void xbt_os_thread_setstacksize(int stack_size) { + size_t def=0; + if(stack_size<0)xbt_die("stack size is negative, maybe it exceeds MAX_INT?\n"); pthread_attr_init(&attr); - pthread_attr_setstacksize (&attr, stack_size); + pthread_attr_getstacksize (&attr, &def); + int res = pthread_attr_setstacksize (&attr, stack_size); + if ( res!=0 ) { + if(res==EINVAL)XBT_WARN("Thread stack size is either < PTHREAD_STACK_MIN, > the max limit of the system, or perhaps not a multiple of PTHREAD_STACK_MIN - The parameter was ignored"); + else XBT_WARN("unknown error in pthread stacksize setting"); + + pthread_attr_setstacksize (&attr, def); + } thread_attr_inited=1; }