Skip to content

Commit

Permalink
Fix some even-more-verbose GCC warnings in the examples
Browse files Browse the repository at this point in the history
  • Loading branch information
nmathewson committed Feb 2, 2010
1 parent 6f89afc commit 1be97f9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 22 deletions.
4 changes: 2 additions & 2 deletions Ref4_event.txt
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,9 @@ void main_loop(evutil_socket_t fd1, evutil_socket_t fd2)
nonblocking. */

ev1 = event_new(base, fd1, EV_TIMEOUT|EV_READ|EV_PERSIST, cb_func,
"Reading event");
(char*)"Reading event");
ev2 = event_new(base, fd2, EV_WRITE|EV_PERSIST, cb_func,
"Writing event");
(char*)"Writing event");

event_add(ev1, &five_seconds);
event_add(ev2, NULL);
Expand Down
44 changes: 24 additions & 20 deletions Ref7_evbuffer.txt
Original file line number Diff line number Diff line change
Expand Up @@ -666,26 +666,30 @@ if (evbuffer_commit_space(buf, v, i) < 0)
DO NOT IMITATE THIS CODE. */
struct evbuffer_iovec v[2];

/* Do not use the pointers from evbuffer_reserve_space() after
calling any functions that modify the buffer. */
evbuffer_reserve_space(buf, 1024, v, 2);
evbuffer_add(buf, "X", 1);
/* WRONG: This next line won't work if evbuffer_add needed to rearrange
the buffer's contents. It might even crash your program. Instead,
you add the data before calling evbuffer_reserve_space. */
memset(v[0].iov_base, 'Y', v[0].iov_len-1);
evbuffer_commit_space(buf, v, 1);

/* Do not modify the iov_base pointers. */
char *data = "Here is some data";
evbuffer_reserve_space(buf, strlen(data), v, 1);
/* WRONG: The next line will not do what you want. Instead, you
should _copy_ the contents of data into v[0].iov_base. */
v[0].iov_base = data;
v[0].iov_len = strlen(data);
/* In this case, evbuffer_commit_space might give an error if you're
lucky */
evbuffer_commit_space(buf, v, 1);
{
/* Do not use the pointers from evbuffer_reserve_space() after
calling any functions that modify the buffer. */
evbuffer_reserve_space(buf, 1024, v, 2);
evbuffer_add(buf, "X", 1);
/* WRONG: This next line won't work if evbuffer_add needed to rearrange
the buffer's contents. It might even crash your program. Instead,
you add the data before calling evbuffer_reserve_space. */
memset(v[0].iov_base, 'Y', v[0].iov_len-1);
evbuffer_commit_space(buf, v, 1);
}

{
/* Do not modify the iov_base pointers. */
const char *data = "Here is some data";
evbuffer_reserve_space(buf, strlen(data), v, 1);
/* WRONG: The next line will not do what you want. Instead, you
should _copy_ the contents of data into v[0].iov_base. */
v[0].iov_base = (char*) data;
v[0].iov_len = strlen(data);
/* In this case, evbuffer_commit_space might give an error if you're
lucky */
evbuffer_commit_space(buf, v, 1);
}
--------

These functions have existed with their present interfaces since Libevent
Expand Down

0 comments on commit 1be97f9

Please sign in to comment.