diff --git a/vlib/builtin/string.v b/vlib/builtin/string.v index a5c04759ee..c465e451ef 100644 --- a/vlib/builtin/string.v +++ b/vlib/builtin/string.v @@ -769,7 +769,7 @@ pub fn (s []string) join_lines() string { pub fn (s string) reverse() string { mut res := string { len: s.len - str: malloc(s.len + 1) + str: malloc(s.len) } for i := s.len - 1; i >= 0; i-- { diff --git a/vlib/builtin/string_test.v b/vlib/builtin/string_test.v index 3c142ebc07..d112e0db49 100644 --- a/vlib/builtin/string_test.v +++ b/vlib/builtin/string_test.v @@ -293,3 +293,9 @@ fn test_all_after() { assert q == 'hello' } +fn test_reverse() { + s := 'hello' + assert s.reverse() == 'olleh' + t := '' + assert t.reverse() == t +}