mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
encoding: append 0
to strings for compatibility (#10249)
This commit is contained in:
parent
0ff2d9ef78
commit
bd467f94ab
@ -35,7 +35,8 @@ pub fn decode_str(data string) string {
|
||||
return ''
|
||||
}
|
||||
unsafe {
|
||||
buffer := malloc(size)
|
||||
buffer := malloc(size + 1)
|
||||
buffer[size] = 0
|
||||
return tos(buffer, decode_in_buffer(data, buffer))
|
||||
}
|
||||
}
|
||||
@ -61,7 +62,8 @@ fn alloc_and_encode(src &byte, len int) string {
|
||||
return ''
|
||||
}
|
||||
unsafe {
|
||||
buffer := malloc(size)
|
||||
buffer := malloc(size + 1)
|
||||
buffer[size] = 0
|
||||
return tos(buffer, encode_from_buffer(buffer, src, len))
|
||||
}
|
||||
}
|
||||
|
@ -197,12 +197,15 @@ pub fn string_from_set(charset string, len int) string {
|
||||
if len == 0 {
|
||||
return ''
|
||||
}
|
||||
mut buf := unsafe { malloc(len) }
|
||||
mut buf := unsafe { malloc(len + 1) }
|
||||
for i in 0 .. len {
|
||||
unsafe {
|
||||
buf[i] = charset[intn(charset.len)]
|
||||
}
|
||||
}
|
||||
unsafe {
|
||||
buf[len] = 0
|
||||
}
|
||||
return unsafe { buf.vstring_with_len(len) }
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user