Browse Source

bgpd: random() returns long

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>
David Lamparter 7 years ago
parent
commit
8c9cd85631
1 changed files with 4 additions and 4 deletions
  1. 4 4
      bgpd/bgp_routemap.c

+ 4 - 4
bgpd/bgp_routemap.c

@@ -826,12 +826,12 @@ route_match_probability (void *rule, struct prefix *prefix,
   r = (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;
         }
@@ -843,7 +843,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
@@ -853,7 +853,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)
     {