[PATCH] libosmo-netif[master]: examples/stream-server.c: use read() rc instead of strlen()

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Sat Nov 26 12:57:14 UTC 2016


Review at  https://gerrit.osmocom.org/1307

examples/stream-server.c: use read() rc instead of strlen()

Fixes: CID#57922
Change-Id: Ibaafdd49d9446a12fe7d0e2f5b2039da3ffc7ea9
---
M examples/stream-server.c
1 file changed, 4 insertions(+), 2 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmo-netif refs/changes/07/1307/1

diff --git a/examples/stream-server.c b/examples/stream-server.c
index 82fb20a..c1bfd66 100644
--- a/examples/stream-server.c
+++ b/examples/stream-server.c
@@ -93,6 +93,8 @@
 	int ret;
 
 	ret = read(STDIN_FILENO, buf, sizeof(buf));
+	if (ret < 1)
+		return 0;
 
 	LOGP(DSTREAMTEST, LOGL_NOTICE, "read %d byte from keyboard\n", ret);
 
@@ -106,8 +108,8 @@
 		LOGP(DSTREAMTEST, LOGL_ERROR, "cannot allocate message\n");
 		return 0;
 	}
-	ptr = msgb_put(msg, strlen(buf));
-	memcpy(ptr, buf, strlen(buf));
+	ptr = msgb_put(msg, ret);
+	memcpy(ptr, buf, ret);
 	osmo_stream_srv_send(conn, msg);
 
 	LOGP(DSTREAMTEST, LOGL_NOTICE, "message of %d bytes sent\n", msg->len);

-- 
To view, visit https://gerrit.osmocom.org/1307
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibaafdd49d9446a12fe7d0e2f5b2039da3ffc7ea9
Gerrit-PatchSet: 1
Gerrit-Project: libosmo-netif
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list