summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexandre Ratchov <ratchov@cvs.openbsd.org>2017-07-20 10:26:28 +0000
committerAlexandre Ratchov <ratchov@cvs.openbsd.org>2017-07-20 10:26:28 +0000
commitfbd4ac5642a06123b9d1dc599031fca593683edc (patch)
treea04bd9ea118a2b0a9d0ed84e06ac8c2e44b47ca4
parent744dcede15f77172fbc18296cecc747b7b8a324b (diff)
Add comments to explain correct code that might look wrong.
-rw-r--r--usr.bin/sndiod/sock.c11
1 files changed, 10 insertions, 1 deletions
diff --git a/usr.bin/sndiod/sock.c b/usr.bin/sndiod/sock.c
index 38d55c4816c..c7fb94d2ffa 100644
--- a/usr.bin/sndiod/sock.c
+++ b/usr.bin/sndiod/sock.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: sock.c,v 1.19 2016/10/27 04:37:47 ratchov Exp $ */
+/* $OpenBSD: sock.c,v 1.20 2017/07/20 10:26:27 ratchov Exp $ */
/*
* Copyright (c) 2008-2012 Alexandre Ratchov <alex@caoua.org>
*
@@ -540,6 +540,10 @@ sock_wdata(struct sock *f)
return 1;
}
while (f->wtodo > 0) {
+ /*
+ * f->slot and f->midi are set by sock_hello(), so
+ * count is always properly initialized
+ */
if (f->slot)
data = abuf_rgetblk(&f->slot->sub.buf, &count);
else if (f->midi)
@@ -1508,6 +1512,11 @@ sock_write(struct sock *f)
case SOCK_WMSG:
if (!sock_wmsg(f))
return 0;
+ /*
+ * f->wmsg is either build by sock_buildmsg() or
+ * copied from f->rmsg (in the SOCK_RRET state), so
+ * it's safe.
+ */
if (ntohl(f->wmsg.cmd) != AMSG_DATA) {
f->wstate = SOCK_WIDLE;
f->wtodo = 0xdeadbeef;