1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

examples: fix crash when running examples/ws/client.v outside of valgrind

This commit is contained in:
Delyan Angelov
2020-07-22 18:42:57 +03:00
parent b0d76c59f7
commit ebbc7bd471
4 changed files with 14 additions and 11 deletions

View File

@@ -6,7 +6,7 @@ fn (mut ws Client) read_handshake(seckey string) {
max_buffer := 1024
buffer_size := 1
mut buffer := malloc(max_buffer)
for bytes_read <= max_buffer {
for bytes_read < max_buffer - 1 {
mut res := 0
unsafe {
res = ws.read_from_server(buffer + bytes_read, buffer_size)
@@ -21,7 +21,7 @@ fn (mut ws Client) read_handshake(seckey string) {
}
bytes_read += buffer_size
}
buffer[max_buffer + 1] = `\0`
buffer[max_buffer - 1] = `\0`
ws.handshake_handler(string(byteptr(buffer)), seckey)
}