From 95ab6ca55750a390d2be4c28b842ece93bfea4d8 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Sun, 7 Dec 2014 03:36:12 +0100 Subject: [PATCH] libev: clean cast abuse assuming that you can cast to the first field of an struct is very risky Signed-off-by: Alejandro Mery --- lib/libev.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/libev.c b/lib/libev.c index 04a4b5be..eff7197f 100644 --- a/lib/libev.c +++ b/lib/libev.c @@ -33,7 +33,7 @@ static void libwebsocket_accept_cb(struct ev_loop *loop, struct ev_io *watcher, int revents) { struct libwebsocket_pollfd eventfd; - struct lws_io_watcher *lws_io = (struct lws_io_watcher *)watcher; + struct lws_io_watcher *lws_io = container_of(watcher, struct lws_io_watcher, watcher); struct libwebsocket_context *context = lws_io->context; if (revents & EV_ERROR) @@ -65,8 +65,8 @@ libwebsocket_initloop( int status = 0; int backend; const char * backend_name; - struct ev_io *w_accept = (ev_io *)&context->w_accept; - struct ev_signal *w_sigint = (ev_signal *)&context->w_sigint; + struct ev_io *w_accept = &context->w_accept.watcher; + struct ev_signal *w_sigint = &context->w_sigint.watcher; if (!loop) loop = ev_default_loop(0);