Commit e7381662 authored by Dan Williams's avatar Dan Williams
Browse files

trivial: don't shadow rand(3)

Reported by Jordan Messina

(cherry picked from commit 365ca198)
parent b59a82d8
......@@ -1830,9 +1830,9 @@ test_ip4_netmask_to_prefix (void)
{
int i, j;
GRand *rand = g_rand_new ();
GRand *r = g_rand_new ();
g_rand_set_seed (rand, 1);
g_rand_set_seed (r, 1);
for (i = 2; i<=32; i++) {
guint32 netmask = nm_utils_ip4_prefix_to_netmask (i);
......@@ -1841,11 +1841,11 @@ test_ip4_netmask_to_prefix (void)
g_assert_cmpint (i, ==, nm_utils_ip4_netmask_to_prefix (netmask));
for (j = 0; j < 2*i; j++) {
guint32 r = g_rand_int (rand);
guint32 n = g_rand_int (r);
guint32 netmask_holey;
guint32 prefix_holey;
netmask_holey = (netmask & r) | netmask_lowest_bit;
netmask_holey = (netmask & n) | netmask_lowest_bit;
if (netmask_holey == netmask)
continue;
......@@ -1858,7 +1858,7 @@ test_ip4_netmask_to_prefix (void)
}
}
g_rand_free (rand);
g_rand_free (r);
}
#define ASSERT_CHANGED(statement) \
......
......@@ -14465,10 +14465,10 @@ static void
test_svUnescape ()
{
int len, repeat, i, k;
GRand *rand = g_rand_new ();
GRand *r = g_rand_new ();
guint32 seed = g_random_int ();
 
g_rand_set_seed (rand, seed);
g_rand_set_seed (r, seed);
 
test_svUnescape_assert ("");
test_svUnescape_assert ("'");
......@@ -14489,16 +14489,16 @@ test_svUnescape ()
 
/* fill the entire string with random. */
for (i = 0; i < len; i++)
s[i] = g_rand_int (rand);
s[i] = g_rand_int (r);
 
/* randomly place escape characters into the string */
k = g_rand_int (rand) % (len);
k = g_rand_int (r) % (len);
while (k-- > 0)
s[g_rand_int (rand) % len] = '\\';
s[g_rand_int (r) % len] = '\\';
 
if (len > 1) {
/* quote the string. */
k = g_rand_int (rand) % (10);
k = g_rand_int (r) % (10);
if (k < 4) {
char quote = k < 2 ? '"' : '\'';
 
......@@ -14514,7 +14514,7 @@ test_svUnescape ()
g_free (s);
}
 
g_rand_free (rand);
g_rand_free (r);
}
 
 
......
......@@ -179,51 +179,51 @@ ip6_address_clear_host_address_reference (struct in6_addr *dst, struct in6_addr
}
static void
_randomize_in6_addr (struct in6_addr *addr, GRand *rand)
_randomize_in6_addr (struct in6_addr *addr, GRand *r)
{
int i;
for (i=0; i < 4; i++)
((guint32 *)addr)[i] = g_rand_int (rand);
((guint32 *)addr)[i] = g_rand_int (r);
}
static void
test_nm_utils_ip6_address_clear_host_address (void)
{
GRand *rand = g_rand_new ();
GRand *r = g_rand_new ();
int plen, i;
g_rand_set_seed (rand, 0);
g_rand_set_seed (r, 0);
for (plen = 0; plen <= 128; plen++) {
for (i =0; i<50; i++) {
struct in6_addr addr_src, addr_ref;
struct in6_addr addr1, addr2;
_randomize_in6_addr (&addr_src, rand);
_randomize_in6_addr (&addr_ref, rand);
_randomize_in6_addr (&addr1, rand);
_randomize_in6_addr (&addr2, rand);
_randomize_in6_addr (&addr_src, r);
_randomize_in6_addr (&addr_ref, r);
_randomize_in6_addr (&addr1, r);
_randomize_in6_addr (&addr2, r);
addr1 = addr_src;
ip6_address_clear_host_address_reference (&addr_ref, &addr1, plen);
_randomize_in6_addr (&addr1, rand);
_randomize_in6_addr (&addr2, rand);
_randomize_in6_addr (&addr1, r);
_randomize_in6_addr (&addr2, r);
addr1 = addr_src;
nm_utils_ip6_address_clear_host_address (&addr2, &addr1, plen);
g_assert_cmpint (memcmp (&addr1, &addr_src, sizeof (struct in6_addr)), ==, 0);
g_assert_cmpint (memcmp (&addr2, &addr_ref, sizeof (struct in6_addr)), ==, 0);
/* test for self assignment/inplace update. */
_randomize_in6_addr (&addr1, rand);
_randomize_in6_addr (&addr1, r);
addr1 = addr_src;
nm_utils_ip6_address_clear_host_address (&addr1, &addr1, plen);
g_assert_cmpint (memcmp (&addr1, &addr_ref, sizeof (struct in6_addr)), ==, 0);
}
}
g_rand_free (rand);
g_rand_free (r);
}
/*******************************************/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment