encoding: append `0` to strings for compatibility (#10249)
parent
0ff2d9ef78
commit
bd467f94ab
|
@ -35,7 +35,8 @@ pub fn decode_str(data string) string {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
buffer := malloc(size)
|
buffer := malloc(size + 1)
|
||||||
|
buffer[size] = 0
|
||||||
return tos(buffer, decode_in_buffer(data, buffer))
|
return tos(buffer, decode_in_buffer(data, buffer))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -61,7 +62,8 @@ fn alloc_and_encode(src &byte, len int) string {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
unsafe {
|
unsafe {
|
||||||
buffer := malloc(size)
|
buffer := malloc(size + 1)
|
||||||
|
buffer[size] = 0
|
||||||
return tos(buffer, encode_from_buffer(buffer, src, len))
|
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 {
|
if len == 0 {
|
||||||
return ''
|
return ''
|
||||||
}
|
}
|
||||||
mut buf := unsafe { malloc(len) }
|
mut buf := unsafe { malloc(len + 1) }
|
||||||
for i in 0 .. len {
|
for i in 0 .. len {
|
||||||
unsafe {
|
unsafe {
|
||||||
buf[i] = charset[intn(charset.len)]
|
buf[i] = charset[intn(charset.len)]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
unsafe {
|
||||||
|
buf[len] = 0
|
||||||
|
}
|
||||||
return unsafe { buf.vstring_with_len(len) }
|
return unsafe { buf.vstring_with_len(len) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue