[asterisk-commits] tilghman: trunk r104705 - in /trunk: ./ main/manager.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Feb 27 12:20:36 CST 2008


Author: tilghman
Date: Wed Feb 27 12:20:35 2008
New Revision: 104705

URL: http://svn.digium.com/view/asterisk?view=rev&rev=104705
Log:
Merged revisions 104704 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.4

........
r104704 | tilghman | 2008-02-27 12:15:10 -0600 (Wed, 27 Feb 2008) | 2 lines

Ensure the session ID can't be 0.

........

Modified:
    trunk/   (props changed)
    trunk/main/manager.c

Propchange: trunk/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Modified: trunk/main/manager.c
URL: http://svn.digium.com/view/asterisk/trunk/main/manager.c?view=diff&rev=104705&r1=104704&r2=104705
==============================================================================
--- trunk/main/manager.c (original)
+++ trunk/main/manager.c Wed Feb 27 12:20:35 2008
@@ -3443,7 +3443,12 @@
 		ast_mutex_init(&s->__lock);
 		ast_mutex_lock(&s->__lock);
 		s->inuse = 1;
-		s->managerid = (rand() ^ (unsigned long) s) | 1;	/* make sure it is non-zero */
+		/*!\note There is approximately a 1 in 1.8E19 chance that the following
+		 * calculation will produce 0, which is an invalid ID, but due to the
+		 * properties of the rand() function (and the constantcy of s), that
+		 * won't happen twice in a row.
+		 */
+		while ((s->managerid = rand() ^ (unsigned long) s) == 0);
 		s->last_ev = grab_last();
 		AST_LIST_LOCK(&sessions);
 		AST_LIST_INSERT_HEAD(&sessions, s, list);




More information about the asterisk-commits mailing list