Skip to content

Commit e2db6c7

Browse files
committed
time,hash,rand: tag more functions with an explicit @[ignore_overflow] or with explicit casts (where needed)
1 parent ea791d0 commit e2db6c7

File tree

12 files changed

+18
-14
lines changed

12 files changed

+18
-14
lines changed

vlib/hash/wyhash.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ const wyp2 = u64(0x8ebc6af09c88c6e3)
2121
const wyp3 = u64(0x589965cc75374cc3)
2222
const wyp4 = u64(0x1d8e4e27c47d124f)
2323

24-
@[inline]
24+
@[ignore_overflow; inline]
2525
fn wyrotr(v u64, k u32) u64 {
2626
return (v >> k) | (v << (64 - k))
2727
}
2828

2929
// wymum returns a hash by performing multiply and mix on `a` and `b`.
30-
@[inline]
30+
@[ignore_overflow; inline]
3131
pub fn wymum(a u64, b u64) u64 {
3232
/*
3333
mut r := u128(a)

vlib/rand/mt19937/mt19937.v

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ fn get_first_state(seed_data []u32) []u64 {
7272
}
7373

7474
// calculate_state returns a random state array calculated from the `seed_data`.
75+
@[ignore_overflow]
7576
fn calculate_state(seed_data []u32, mut state []u64) []u64 {
7677
lo := u64(seed_data[0])
7778
hi := u64(seed_data[1])
@@ -145,7 +146,7 @@ pub fn (mut rng MT19937RNG) u32() u32 {
145146
const mag01 = [u64(0), u64(matrix_a)]
146147

147148
// u64 returns a pseudorandom 64bit int in range `[0, 2⁶⁴)`.
148-
@[direct_array_access; inline]
149+
@[direct_array_access; ignore_overflow; inline]
149150
pub fn (mut rng MT19937RNG) u64() u64 {
150151
mut x := u64(0)
151152
mut i := int(0)

vlib/rand/musl/musl_rng.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ fn temper(prev u32) u32 {
7070
}
7171

7272
// u32 returns a pseudorandom 32-bit unsigned integer (`u32`).
73+
@[ignore_overflow]
7374
pub fn (mut rng MuslRNG) u32() u32 {
7475
rng.state = rng.state * 1103515245 + 12345
7576
// We are not dividing by 2 (or shifting right by 1)

vlib/rand/pcg32/pcg32.v

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ mut:
2121
// seed seeds the PCG32RNG with 4 `u32` values.
2222
// The first 2 represent the 64-bit initial state as `[lower 32 bits, higher 32 bits]`
2323
// The last 2 represent the 64-bit stream/step of the PRNG.
24+
@[ignore_overflow]
2425
pub fn (mut rng PCG32RNG) seed(seed_data []u32) {
2526
if seed_data.len != 4 {
2627
eprintln('PCG32RNG needs 4 u32s to be seeded. First two the initial state and the last two the stream/step. Both in little endian format: [lower, higher].')
@@ -69,7 +70,7 @@ pub fn (mut rng PCG32RNG) u16() u16 {
6970
}
7071

7172
// u32 returns a pseudorandom unsigned `u32`.
72-
@[inline]
73+
@[ignore_overflow; inline]
7374
pub fn (mut rng PCG32RNG) u32() u32 {
7475
oldstate := rng.state
7576
rng.state = oldstate * (6364136223846793005) + rng.inc

vlib/rand/rand.c.v

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ pub fn new_uuid_v7_session() UUIDSession {
8282
}
8383

8484
// next get a new uuid_v7 from current session.
85+
@[ignore_overflow]
8586
pub fn (mut u UUIDSession) next() string {
8687
timestamp := u64(time.now().unix_nano())
8788
// make place for holding 4 bits `version`

vlib/rand/seed/seed.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module seed
66
import time
77

88
// nr_next returns a next value based on the previous value `prev`.
9-
@[inline]
9+
@[ignore_overflow; inline]
1010
fn nr_next(prev u32) u32 {
1111
return prev * 1664525 + 1013904223
1212
}

vlib/rand/splitmix64/splitmix64.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ pub fn (mut rng SplitMix64RNG) u32() u32 {
7575
}
7676

7777
// u64 returns a pseudorandom 64bit int in range `[0, 2⁶⁴)`.
78-
@[inline]
78+
@[ignore_overflow; inline]
7979
pub fn (mut rng SplitMix64RNG) u64() u64 {
8080
rng.state += (0x9e3779b97f4a7c15)
8181
mut z := rng.state

vlib/rand/wyrand/wyrand.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn (mut rng WyRandRNG) u32() u32 {
8282
}
8383

8484
// u64 returns a pseudorandom 64bit int in range `[0, 2⁶⁴)`.
85-
@[inline]
85+
@[ignore_overflow; inline]
8686
pub fn (mut rng WyRandRNG) u64() u64 {
8787
unsafe {
8888
mut seed1 := rng.state

vlib/rand/xoroshiro128pp/xoros128pp.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub fn (mut rng XOROS128PPRNG) u32() u32 {
8383
}
8484

8585
// u64 returns a pseudorandom 64-bit unsigned `u64`.
86-
@[inline]
86+
@[ignore_overflow; inline]
8787
pub fn (mut rng XOROS128PPRNG) u64() u64 {
8888
oldstate0 := rng.state0
8989
mut oldstate1 := rng.state1

vlib/time/operator_test.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ fn test_time2_copied_from_time1_should_be_equal() {
371371
fn test_subtract() {
372372
d_seconds := 3
373373
d_nanoseconds := 13
374-
duration := d_seconds * second + d_nanoseconds * nanosecond
374+
duration := i64(d_seconds) * second + d_nanoseconds * nanosecond
375375
t1 := new(Time{
376376
year: 2000
377377
month: 5

0 commit comments

Comments
 (0)