From: Mark Wooding Date: Wed, 14 Mar 2012 18:50:01 +0000 (+0000) Subject: Ignore boring return codes properly. X-Git-Tag: 1.0.0pre11~39 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~mdw/git/tripe/commitdiff_plain/23df0e5b6d5dfe65beaf6fee394746bfbf574035 Ignore boring return codes properly. The warning about variables assigned values and then ignored is useful, as are warnings about ignored return codes sometimes. But sometimes ignoring things really is the right answer. --- diff --git a/client/tripectl.c b/client/tripectl.c index f818de8d..438edf37 100644 --- a/client/tripectl.c +++ b/client/tripectl.c @@ -65,7 +65,6 @@ #include "util.h" #undef sun -#define IGNORE(x) do if (x); while (0) /*----- Data structures ---------------------------------------------------*/ diff --git a/common/util.h b/common/util.h index 1928c042..acdc0f6e 100644 --- a/common/util.h +++ b/common/util.h @@ -37,6 +37,18 @@ extern "C" { #endif +/*----- Macros ------------------------------------------------------------*/ + +/* --- @IGNORE@ --- * + * + * Arguments: @expr@ = an expression whose value is to be ignored + * + * Use: Ignores the value of an expression, even if compilers want + * us not to. + */ + +#define IGNORE(expr) do { if (expr) ; } while (0) + /*----- Functions provided ------------------------------------------------*/ /* --- @u_quotify@ --- * diff --git a/pkstream/pkstream.c b/pkstream/pkstream.c index 665b80ea..d431b820 100644 --- a/pkstream/pkstream.c +++ b/pkstream/pkstream.c @@ -54,6 +54,8 @@ #include #include +#include "util.h" + /*----- Data structures ---------------------------------------------------*/ typedef struct pk { @@ -120,7 +122,6 @@ static void rdtcp(octet *b, size_t sz, pkbuf *pk, size_t *k, void *vp) { pkstream *p = vp; size_t pksz; - int hunoz; if (!sz) { doclose(p); @@ -128,7 +129,7 @@ static void rdtcp(octet *b, size_t sz, pkbuf *pk, size_t *k, void *vp) } pksz = LOAD16(b); if (pksz + 2 == sz) { - hunoz = write(fd_udp, b + 2, pksz); + IGNORE(write(fd_udp, b + 2, pksz)); selpk_want(&p->p, 2); } else { selpk_want(&p->p, pksz + 2); diff --git a/proxy/tripe-mitm.c b/proxy/tripe-mitm.c index 3686b7ba..4b0e4470 100644 --- a/proxy/tripe-mitm.c +++ b/proxy/tripe-mitm.c @@ -67,6 +67,8 @@ #include #include +#include "util.h" + /*----- Data structures ---------------------------------------------------*/ typedef struct peer { @@ -406,10 +408,8 @@ static void adddelay(filter *f, unsigned ac, char **av) static void dosend(filter *f, const octet *buf, size_t sz) { - int hunoz; - printf("send to `%s'\n", f->p_to->name); - hunoz = write(f->p_to->sf.fd, buf, sz); + IGNORE(write(f->p_to->sf.fd, buf, sz)); } static void addsend(filter *f, unsigned ac, char **av) diff --git a/server/tun-bsd.c b/server/tun-bsd.c index b945c7dd..2c872997 100644 --- a/server/tun-bsd.c +++ b/server/tun-bsd.c @@ -119,13 +119,11 @@ static tunnel *t_create(peer *p, int fd, char **ifn) static void t_inject(tunnel *t, buf *b) { - int hunoz; - IF_TRACING(T_TUNNEL, { trace(T_TUNNEL, "tun-bsd: inject decrypted packet"); trace_block(T_PACKET, "tun-bsd: packet contents", BBASE(b), BLEN(b)); }) - hunoz = write(t->f.fd, BBASE(b), BLEN(b)); + IGNORE(write(t->f.fd, BBASE(b), BLEN(b))); } /* --- @t_destroy@ --- * diff --git a/server/tun-linux.c b/server/tun-linux.c index 33451746..10456e35 100644 --- a/server/tun-linux.c +++ b/server/tun-linux.c @@ -125,13 +125,11 @@ static tunnel *t_create(peer *p, int fd, char **ifn) static void t_inject(tunnel *t, buf *b) { - int hunoz; - IF_TRACING(T_TUNNEL, { trace(T_TUNNEL, "tun-linux: inject decrypted packet"); trace_block(T_PACKET, "tunnel: packet contents", BBASE(b), BLEN(b)); }) - hunoz = write(t->f.fd, BBASE(b), BLEN(b)); + IGNORE(write(t->f.fd, BBASE(b), BLEN(b))); } /* --- @t_destroy@ --- * diff --git a/server/tun-unet.c b/server/tun-unet.c index 719830bf..19dc5e60 100644 --- a/server/tun-unet.c +++ b/server/tun-unet.c @@ -125,13 +125,11 @@ static tunnel *t_create(peer *p, int fd, char **ifn) static void t_inject(tunnel *t, buf *b) { - int hunoz; - IF_TRACING(T_TUNNEL, { trace(T_TUNNEL, "tun-unet: inject decrypted packet"); trace_block(T_PACKET, "tun-unet: packet contents", BBASE(b), BLEN(b)); }) - hunoz = write(t->f.fd, BBASE(b), BLEN(b)); + IGNORE(write(t->f.fd, BBASE(b), BLEN(b))); } /* --- @t_destroy@ --- *