libevent evbuffer bug
今天发现 libevent 2.0.22 一个坑爹的bug,导致消息混乱。查找问题浪费一天,复现代码如下
#include <event2/buffer.h> #include <stdio.h> #include <string.h> // libevent-2.0.22-stable bug, but libevent 2.0.21 worked well int main(int argc, char **argv) { evbuffer *buf = evbuffer_new(); evbuffer_expand(buf, 12); evbuffer_add(buf, ": first line \n", 14); // force to add a new chain evbuffer_expand(buf, 2048); // add always add to the last chain, but last_with_datap is not changed accordingly evbuffer_add(buf, ": second line \n", 15); //evbuffer_expand(buf, 30); // printf try expand buffer and return the first chain, then add to the first chain evbuffer_add_printf(buf, ": last line\n"); fprintf(stdout, "%*s\n", evbuffer_get_length(buf), evbuffer_pullup(buf, -1)); return 0; }
结果在 libevent 2.0.22 输出
: first line
: last line
: second line
libevent 2.0.21 正常
: first line
: second line
: last line