Skip to content
This repository has been archived by the owner on Nov 20, 2022. It is now read-only.

tcp_echo_server malloc buff is not cleared, and the reception is garbled #77

Open
hh-kai opened this issue Nov 16, 2019 · 0 comments
Open

Comments

@hh-kai
Copy link

hh-kai commented Nov 16, 2019

void alloc_buffer(uv_handle_t *handle, size_t suggested_size, uv_buf_t buf) {
buf->base = (char
) malloc(suggested_size);
memset(buf->base, 0, suggested_size); // set 0
buf->len = suggested_size;
}

After malloc, memset should be added, otherwise the received data may be scrambled. Actually, the test will be scrambled

@hh-kai hh-kai changed the title tcp_echo_server malloc buff未清空 接收有乱码 tcp_echo_server malloc buff is not cleared, and the reception is garbled Nov 16, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant