Skip to content

Commit

Permalink
fix: Clone unsafely created string saved in arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
prantlf committed Apr 17, 2024
1 parent fa3b203 commit 1e300ab
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/parse.v
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ fn (mut p Parser) parse_number(i int) !(f64, int) {
n := C.strtod(unsafe { p.str.str + i }, &end)
if C.errno != 0 {
val := if end != unsafe { nil } {
unsafe { tos(p.str.str + i, &u8(end) - p.str.str + i) }
unsafe { tos(p.str.str + i, &u8(end) - p.str.str + i).clone() }
} else {
unsafe { tos(p.str.str + i, 1) }
}
Expand All @@ -354,7 +354,7 @@ fn (mut p Parser) parse_string(from int, quote u8) !(string, int) {
first := from + 1
mut i, esc := p.detect_escape(first, quote)!
if !esc {
return unsafe { tos(p.str.str + first, i - first) }, i + 1
return unsafe { tos(p.str.str + first, i - first).clone() }, i + 1
}
mut builder := strings.new_builder(64)
for j := first; j < i; j++ {
Expand Down

0 comments on commit 1e300ab

Please # to comment.