From: David Lamparter Date: Sun, 19 Apr 2015 12:40:02 +0000 (+0200) Subject: bgpd: random() returns long X-Git-Tag: frr-2.0-rc1~752 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=37e20390bdb76366b698665637438d163223937b;p=matthieu%2Ffrr.git 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 (cherry picked from commit 8c9cd85631b77fac0bc30ffb9f23b29c466d31c4) --- diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index 2a7b33d987..3ec2087650 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -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) {