From 924650039110ed1b7725e290d67740c8fe2bcbe0 Mon Sep 17 00:00:00 2001 From: zfl9 Date: Sat, 7 Mar 2020 16:13:34 +0800 Subject: suppress gcc warning in code --- dns2tcp.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/dns2tcp.c b/dns2tcp.c index be45d83..39d00a3 100644 --- a/dns2tcp.c +++ b/dns2tcp.c @@ -390,7 +390,8 @@ static void udp_recvmsg_cb(evloop_t *evloop, evio_t *watcher __attribute__((unus parse_socket_addr(&tcpw->srcaddr, g_ipstr_buf, &portno); LOGINF("[udp_recvmsg_cb] recv from %s#%hu, nrecv:%zd", g_ipstr_buf, portno, nrecv); } - *(uint16_t *)tcpw->buffer = htons(nrecv); + uint16_t *msglen_ptr = (void *)tcpw->buffer; + *msglen_ptr = htons(nrecv); /* msg length */ nrecv += 2; /* msglen + msgbuf */ tcpw->nrcvsnd = 0; @@ -457,7 +458,8 @@ static void tcp_connect_cb(evloop_t *evloop, evio_t *watcher, int events __attri static void tcp_sendmsg_cb(evloop_t *evloop, evio_t *watcher, int events __attribute__((unused))) { tcpwatcher_t *tcpw = (void *)watcher; - uint16_t datalen = 2 + ntohs(*(uint16_t *)tcpw->buffer); + uint16_t *msglen_ptr = (void *)tcpw->buffer; + uint16_t datalen = 2 + ntohs(*msglen_ptr); ssize_t nsend = send(watcher->fd, (void *)tcpw->buffer + tcpw->nrcvsnd, datalen - tcpw->nrcvsnd, 0); if (nsend < 0) { if (errno == EAGAIN || errno == EWOULDBLOCK) return; -- cgit v1.2.3