Skip to content

Commit 9e78353

Browse files
committed
Fix maybe uninitialized warnings in random.c
Fixes the following compiler warnings: random.c: In function `random_init`: random.c:416:38: warning: `rng` may be used uninitialized in this function [-Wmaybe-uninitialized] 416 | unsigned int major = rng->version.major; | ~~~~~~~~~~~~^~~~~~ random.c: In function `random_bytes`: random.c:1284:8: warning: `rng` may be used uninitialized in this function [-Wmaybe-uninitialized] 1284 | rng->get_bytes(rnd, ptr, n); | ~~~^~~~~~~~~~~ random.c:1299:34: note: `rng` was declared here 1299 | const rb_random_interface_t *rng; | ^~~ random.c: In function `rand_random_number`: random.c:1606:12: warning: `rng` may be used uninitialized in this function [-Wmaybe-uninitialized] 1606 | return rand_range(obj, rng, rnd, vmax); | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ random.c:1624:34: note: `rng` was declared here 1624 | const rb_random_interface_t *rng; | ^~~ random.c: In function `random_rand`: random.c:1120:15: warning: `rng` may be used uninitialized in this function [-Wmaybe-uninitialized] 1120 | return rng->get_int32(rnd); | ~~~^~~~~~~~~~~ random.c:1573:34: note: `rng` was declared here 1573 | const rb_random_interface_t *rng; | ^~~
1 parent d615dbf commit 9e78353

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

random.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ rand_init(const rb_random_interface_t *rng, rb_random_t *rnd, VALUE seed)
405405
static VALUE
406406
random_init(int argc, VALUE *argv, VALUE obj)
407407
{
408-
const rb_random_interface_t *rng;
408+
const rb_random_interface_t *rng = NULL;
409409
rb_random_t *rnd = try_get_rnd(obj, &rng);
410410

411411
if (!rng) {
@@ -1296,7 +1296,7 @@ rand_bytes(const rb_random_interface_t *rng, rb_random_t *rnd, long n)
12961296
static VALUE
12971297
random_bytes(VALUE obj, VALUE len)
12981298
{
1299-
const rb_random_interface_t *rng;
1299+
const rb_random_interface_t *rng = NULL;
13001300
rb_random_t *rnd = try_get_rnd(obj, &rng);
13011301
return rand_bytes(rng, rnd, NUM2LONG(rb_to_int(len)));
13021302
}
@@ -1570,7 +1570,7 @@ static VALUE rand_random(int argc, VALUE *argv, VALUE obj, const rb_random_inter
15701570
static VALUE
15711571
random_rand(int argc, VALUE *argv, VALUE obj)
15721572
{
1573-
const rb_random_interface_t *rng;
1573+
const rb_random_interface_t *rng = NULL;
15741574
rb_random_t *rnd = try_get_rnd(obj, &rng);
15751575
VALUE v = rand_random(argc, argv, obj, rng, rnd);
15761576
check_random_number(v, argv);
@@ -1621,7 +1621,7 @@ rand_random(int argc, VALUE *argv, VALUE obj, const rb_random_interface_t *rng,
16211621
static VALUE
16221622
rand_random_number(int argc, VALUE *argv, VALUE obj)
16231623
{
1624-
const rb_random_interface_t *rng;
1624+
const rb_random_interface_t *rng = NULL;
16251625
rb_random_t *rnd = try_get_rnd(obj, &rng);
16261626
VALUE v = rand_random(argc, argv, obj, rng, rnd);
16271627
if (NIL_P(v)) v = rand_random(0, 0, obj, rng, rnd);

0 commit comments

Comments
 (0)