Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tb_buffer_memsetp会越界赋值 #207

Closed
duyanning opened this issue Mar 2, 2023 · 2 comments
Closed

tb_buffer_memsetp会越界赋值 #207

duyanning opened this issue Mar 2, 2023 · 2 comments
Labels

Comments

@duyanning
Copy link
Contributor

描述问题

    tb_buffer_t b;
    tb_buffer_init(&b);

    tb_buffer_memncpy(&b, (tb_byte_t const*)"hello", 6); // data[0-5]
    tb_trace_i("%s", tb_buffer_data(&b));

    printf("size: %ld\n", tb_buffer_size(&b));
    printf("maxn: %ld\n", tb_buffer_maxn(&b));
    printf("data[%ld]=%d\n", tb_buffer_size(&b), *((char*)tb_buffer_data(&b)+tb_buffer_size(&b)));
    printf("data[%ld]=%d\n", tb_buffer_size(&b)+1, *((char*)tb_buffer_data(&b)+tb_buffer_size(&b)+1));

    // 此刻,缓冲区中的数据,即从data[0]到data[5]为hello\0
    tb_buffer_memsetp(&b, 4, 65); // 按我的理解,本行会把data[4]到data[5]赋成字符A
    tb_trace_i("%s", tb_buffer_data(&b)); // 然而写入了6个A: hellAAAAAA

    tb_buffer_exit(&b);
@waruqi
Copy link
Member

waruqi commented Mar 2, 2023

我修复了,再试下,dev 分支。。

@waruqi waruqi added the bug label Mar 2, 2023
@waruqi waruqi closed this as completed in aaf266f Mar 2, 2023
@duyanning
Copy link
Contributor Author

我修复了,再试下,dev 分支。。

试了,修好了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants