File tree Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Expand file tree Collapse file tree 2 files changed +8
-3
lines changed Original file line number Diff line number Diff line change @@ -35,7 +35,8 @@ pub fn decode_str(data string) string {
3535 return ''
3636 }
3737 unsafe {
38- buffer := malloc (size)
38+ buffer := malloc (size + 1 )
39+ buffer[size] = 0
3940 return tos (buffer, decode_in_buffer (data, buffer))
4041 }
4142}
@@ -61,7 +62,8 @@ fn alloc_and_encode(src &byte, len int) string {
6162 return ''
6263 }
6364 unsafe {
64- buffer := malloc (size)
65+ buffer := malloc (size + 1 )
66+ buffer[size] = 0
6567 return tos (buffer, encode_from_buffer (buffer, src, len))
6668 }
6769}
Original file line number Diff line number Diff line change @@ -197,12 +197,15 @@ pub fn string_from_set(charset string, len int) string {
197197 if len == 0 {
198198 return ''
199199 }
200- mut buf := unsafe { malloc (len) }
200+ mut buf := unsafe { malloc (len + 1 ) }
201201 for i in 0 .. len {
202202 unsafe {
203203 buf[i] = charset[intn (charset.len)]
204204 }
205205 }
206+ unsafe {
207+ buf[len] = 0
208+ }
206209 return unsafe { buf.vstring_with_len (len) }
207210}
208211
You can’t perform that action at this time.
0 commit comments