]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd: random() returns long
authorDavid Lamparter <equinox@opensourcerouting.org>
Sun, 19 Apr 2015 12:40:02 +0000 (14:40 +0200)
committerDaniel Walton <dwalton@cumulusnetworks.com>
Thu, 26 May 2016 15:33:29 +0000 (15:33 +0000)
bgpd was using unsigned to store a probability value to be used with
random().  That, however, returns long, running into some warnings (and
worst case, if RAND_MAX > UINT_MAX, won't work correctly.

Just use long to shuffle the value around.

Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
(cherry picked from commit 8c9cd85631b77fac0bc30ffb9f23b29c466d31c4)

bgpd/bgp_routemap.c

index 2a7b33d987dcd28d82f81938426084fc289c11db..3ec20876506ca0adfc61ef91d6df682be3b1eaaf 100644 (file)
@@ -899,12 +899,12 @@ route_match_probability (void *rule, struct prefix *prefix,
   r = (unsigned long) rand();
 #endif
 
-  switch (*(unsigned *) rule)
+  switch (*(long *) rule)
   {
     case 0: break;
     case RAND_MAX: return RMAP_MATCH;
     default:
-      if (r < *(unsigned *) rule)
+      if (r < *(long *) rule)
         {
           return RMAP_MATCH;
         }
@@ -916,7 +916,7 @@ route_match_probability (void *rule, struct prefix *prefix,
 static void *
 route_match_probability_compile (const char *arg)
 {
-  unsigned *lobule;
+  long *lobule;
   unsigned  perc;
 
 #if _SVID_SOURCE || _BSD_SOURCE || _XOPEN_SOURCE >= 500
@@ -926,7 +926,7 @@ route_match_probability_compile (const char *arg)
 #endif
 
   perc    = atoi (arg);
-  lobule  = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (unsigned));
+  lobule  = XMALLOC (MTYPE_ROUTE_MAP_COMPILED, sizeof (long));
 
   switch (perc)
     {