Skip to content

Commit f885c7c

Browse files
authored
tests: fix three tests with address errors (#9441)
1 parent 392666e commit f885c7c

File tree

5 files changed

+11
-14
lines changed

5 files changed

+11
-14
lines changed

cmd/tools/vtest-self.v

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,8 @@ const (
2424
'vlib/crypto/rand/crypto_rand_read_test.v',
2525
]
2626
skip_with_fsanitize_address = [
27-
'vlib/encoding/base64/base64_test.v',
2827
'vlib/json/json_test.v',
2928
'vlib/regex/regex_test.v',
30-
'vlib/v/tests/ptr_arithmetic_test.v',
31-
'vlib/v/tests/unsafe_test.v',
3229
'vlib/x/websocket/websocket_test.v',
3330
]
3431
skip_with_fsanitize_undefined = []string{}

vlib/encoding/base64/base64.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const (
1818
// Example: assert base64.decode('ViBpbiBiYXNlIDY0') == 'V in base 64'
1919
pub fn decode(data string) []byte {
2020
size := data.len * 3 / 4
21-
if size <= 0 {
21+
if size <= 0 || data.len % 4 != 0 {
2222
return []
2323
}
2424
unsafe {
@@ -31,7 +31,7 @@ pub fn decode(data string) []byte {
3131
// decode_str is the string variant of decode
3232
pub fn decode_str(data string) string {
3333
size := data.len * 3 / 4
34-
if size <= 0 {
34+
if size <= 0 || data.len % 4 != 0 {
3535
return ''
3636
}
3737
unsafe {

vlib/encoding/base64/base64_test.v

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ fn test_decode() {
4343
assert base64.decode(man_pair.encoded) == man_pair.decoded.bytes()
4444

4545
// Test for incorrect padding.
46-
assert base64.decode('aGk') == 'hi'.bytes()
46+
assert base64.decode('aGk') == ''.bytes()
4747
assert base64.decode('aGk=') == 'hi'.bytes()
48-
assert base64.decode('aGk==') == 'hi'.bytes()
48+
assert base64.decode('aGk==') == ''.bytes()
4949

5050
for i, p in pairs {
5151
got := base64.decode(p.encoded)
@@ -60,9 +60,9 @@ fn test_decode_str() {
6060
assert base64.decode_str(man_pair.encoded) == man_pair.decoded
6161

6262
// Test for incorrect padding.
63-
assert base64.decode_str('aGk') == 'hi'
63+
assert base64.decode_str('aGk') == ''
6464
assert base64.decode_str('aGk=') == 'hi'
65-
assert base64.decode_str('aGk==') == 'hi'
65+
assert base64.decode_str('aGk==') == ''
6666

6767
for i, p in pairs {
6868
got := base64.decode_str(p.encoded)

vlib/v/tests/ptr_arithmetic_test.v

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ fn test_ptr_arithmetic() {
99
p++
1010
p += 2
1111
p = p - 1
12-
assert p == &v + 2
12+
assert ptr_str(p) == ptr_str(&v + 2)
1313
p = p + 1
14-
assert p == &v + 3
14+
assert ptr_str(p) == ptr_str(&v + 3)
1515
r := p++
16-
assert r == &v + 3
17-
assert p == &v + 4
16+
assert ptr_str(r) == ptr_str(&v + 3)
17+
assert ptr_str(p) == ptr_str(&v + 4)
1818
}
1919
}
2020

vlib/v/tests/unsafe_test.v

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ fn test_ptr_infix() {
3636
v := 4
3737
mut q := unsafe {&v - 1}
3838
q = unsafe {q + 3}
39-
assert q == unsafe {&v + 2}
39+
assert ptr_str(q) == ptr_str(unsafe {&v + 2})
4040
}
4141

4242
struct S1 {

0 commit comments

Comments
 (0)