trivial: don't shadow rand(3)
Reported by Jordan Messina (cherry picked from commit 365ca198c0d688e759cd2481d9446ba16f8e78ca)
This commit is contained in:
@@ -1830,9 +1830,9 @@ test_ip4_netmask_to_prefix (void)
|
|||||||
{
|
{
|
||||||
int i, j;
|
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++) {
|
for (i = 2; i<=32; i++) {
|
||||||
guint32 netmask = nm_utils_ip4_prefix_to_netmask (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));
|
g_assert_cmpint (i, ==, nm_utils_ip4_netmask_to_prefix (netmask));
|
||||||
|
|
||||||
for (j = 0; j < 2*i; j++) {
|
for (j = 0; j < 2*i; j++) {
|
||||||
guint32 r = g_rand_int (rand);
|
guint32 n = g_rand_int (r);
|
||||||
guint32 netmask_holey;
|
guint32 netmask_holey;
|
||||||
guint32 prefix_holey;
|
guint32 prefix_holey;
|
||||||
|
|
||||||
netmask_holey = (netmask & r) | netmask_lowest_bit;
|
netmask_holey = (netmask & n) | netmask_lowest_bit;
|
||||||
|
|
||||||
if (netmask_holey == netmask)
|
if (netmask_holey == netmask)
|
||||||
continue;
|
continue;
|
||||||
@@ -1858,7 +1858,7 @@ test_ip4_netmask_to_prefix (void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_rand_free (rand);
|
g_rand_free (r);
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ASSERT_CHANGED(statement) \
|
#define ASSERT_CHANGED(statement) \
|
||||||
|
@@ -14465,10 +14465,10 @@ static void
|
|||||||
test_svUnescape ()
|
test_svUnescape ()
|
||||||
{
|
{
|
||||||
int len, repeat, i, k;
|
int len, repeat, i, k;
|
||||||
GRand *rand = g_rand_new ();
|
GRand *r = g_rand_new ();
|
||||||
guint32 seed = g_random_int ();
|
guint32 seed = g_random_int ();
|
||||||
|
|
||||||
g_rand_set_seed (rand, seed);
|
g_rand_set_seed (r, seed);
|
||||||
|
|
||||||
test_svUnescape_assert ("");
|
test_svUnescape_assert ("");
|
||||||
test_svUnescape_assert ("'");
|
test_svUnescape_assert ("'");
|
||||||
@@ -14489,16 +14489,16 @@ test_svUnescape ()
|
|||||||
|
|
||||||
/* fill the entire string with random. */
|
/* fill the entire string with random. */
|
||||||
for (i = 0; i < len; i++)
|
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 */
|
/* randomly place escape characters into the string */
|
||||||
k = g_rand_int (rand) % (len);
|
k = g_rand_int (r) % (len);
|
||||||
while (k-- > 0)
|
while (k-- > 0)
|
||||||
s[g_rand_int (rand) % len] = '\\';
|
s[g_rand_int (r) % len] = '\\';
|
||||||
|
|
||||||
if (len > 1) {
|
if (len > 1) {
|
||||||
/* quote the string. */
|
/* quote the string. */
|
||||||
k = g_rand_int (rand) % (10);
|
k = g_rand_int (r) % (10);
|
||||||
if (k < 4) {
|
if (k < 4) {
|
||||||
char quote = k < 2 ? '"' : '\'';
|
char quote = k < 2 ? '"' : '\'';
|
||||||
|
|
||||||
@@ -14514,7 +14514,7 @@ test_svUnescape ()
|
|||||||
g_free (s);
|
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
|
static void
|
||||||
_randomize_in6_addr (struct in6_addr *addr, GRand *rand)
|
_randomize_in6_addr (struct in6_addr *addr, GRand *r)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i=0; i < 4; i++)
|
for (i=0; i < 4; i++)
|
||||||
((guint32 *)addr)[i] = g_rand_int (rand);
|
((guint32 *)addr)[i] = g_rand_int (r);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
test_nm_utils_ip6_address_clear_host_address (void)
|
test_nm_utils_ip6_address_clear_host_address (void)
|
||||||
{
|
{
|
||||||
GRand *rand = g_rand_new ();
|
GRand *r = g_rand_new ();
|
||||||
int plen, i;
|
int plen, i;
|
||||||
|
|
||||||
g_rand_set_seed (rand, 0);
|
g_rand_set_seed (r, 0);
|
||||||
|
|
||||||
for (plen = 0; plen <= 128; plen++) {
|
for (plen = 0; plen <= 128; plen++) {
|
||||||
for (i =0; i<50; i++) {
|
for (i =0; i<50; i++) {
|
||||||
struct in6_addr addr_src, addr_ref;
|
struct in6_addr addr_src, addr_ref;
|
||||||
struct in6_addr addr1, addr2;
|
struct in6_addr addr1, addr2;
|
||||||
|
|
||||||
_randomize_in6_addr (&addr_src, rand);
|
_randomize_in6_addr (&addr_src, r);
|
||||||
_randomize_in6_addr (&addr_ref, rand);
|
_randomize_in6_addr (&addr_ref, r);
|
||||||
_randomize_in6_addr (&addr1, rand);
|
_randomize_in6_addr (&addr1, r);
|
||||||
_randomize_in6_addr (&addr2, rand);
|
_randomize_in6_addr (&addr2, r);
|
||||||
|
|
||||||
addr1 = addr_src;
|
addr1 = addr_src;
|
||||||
ip6_address_clear_host_address_reference (&addr_ref, &addr1, plen);
|
ip6_address_clear_host_address_reference (&addr_ref, &addr1, plen);
|
||||||
|
|
||||||
_randomize_in6_addr (&addr1, rand);
|
_randomize_in6_addr (&addr1, r);
|
||||||
_randomize_in6_addr (&addr2, rand);
|
_randomize_in6_addr (&addr2, r);
|
||||||
addr1 = addr_src;
|
addr1 = addr_src;
|
||||||
nm_utils_ip6_address_clear_host_address (&addr2, &addr1, plen);
|
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 (&addr1, &addr_src, sizeof (struct in6_addr)), ==, 0);
|
||||||
g_assert_cmpint (memcmp (&addr2, &addr_ref, sizeof (struct in6_addr)), ==, 0);
|
g_assert_cmpint (memcmp (&addr2, &addr_ref, sizeof (struct in6_addr)), ==, 0);
|
||||||
|
|
||||||
/* test for self assignment/inplace update. */
|
/* test for self assignment/inplace update. */
|
||||||
_randomize_in6_addr (&addr1, rand);
|
_randomize_in6_addr (&addr1, r);
|
||||||
addr1 = addr_src;
|
addr1 = addr_src;
|
||||||
nm_utils_ip6_address_clear_host_address (&addr1, &addr1, plen);
|
nm_utils_ip6_address_clear_host_address (&addr1, &addr1, plen);
|
||||||
g_assert_cmpint (memcmp (&addr1, &addr_ref, sizeof (struct in6_addr)), ==, 0);
|
g_assert_cmpint (memcmp (&addr1, &addr_ref, sizeof (struct in6_addr)), ==, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g_rand_free (rand);
|
g_rand_free (r);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*******************************************/
|
/*******************************************/
|
||||||
|
Reference in New Issue
Block a user