linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Slavomir Kaslev <kaslevs@vmware.com>
To: rostedt@goodmis.org
Cc: linux-trace-devel@vger.kernel.org, slavomir.kaslev@gmail.com
Subject: [PATCH] trace-cmd: Change tracecmd_msg's buf member type to char *
Date: Fri, 22 Mar 2019 18:26:35 +0200	[thread overview]
Message-ID: <20190322162635.30689-1-kaslevs@vmware.com> (raw)

Now that all protocol V3 messages (besides SEND_DATA) use the buffer for text,
it makes sense to have it declared as such and drop a few casts.

This also takes care of undefined behavior caused by void pointer arithmetic in
tracecmd_msg_data_send()/tracecmd_msg_read_data().

Signed-off-by: Slavomir Kaslev <kaslevs@vmware.com>
---
 tracecmd/trace-msg.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/tracecmd/trace-msg.c b/tracecmd/trace-msg.c
index a91b211..9a27141 100644
--- a/tracecmd/trace-msg.c
+++ b/tracecmd/trace-msg.c
@@ -104,7 +104,7 @@ struct tracecmd_msg {
 		struct tracecmd_msg_tinit	tinit;
 		struct tracecmd_msg_rinit	rinit;
 	};
-	void					*buf;
+	char					*buf;
 } __attribute__((packed));
 
 static int msg_buf_len(struct tracecmd_msg *msg)
@@ -436,7 +436,7 @@ int tracecmd_msg_send_init_data(struct tracecmd_msg_handle *msg_handle,
 		goto error;
 	}
 
-	if (((char *)msg.buf)[buf_len-1] != '\0') {
+	if (msg.buf[buf_len-1] != '\0') {
 		ret = -EINVAL;
 		goto error;
 	}
@@ -448,7 +448,7 @@ int tracecmd_msg_send_init_data(struct tracecmd_msg_handle *msg_handle,
 		goto out;
 	}
 
-	buf_end = (char *)msg.buf + buf_len;
+	buf_end = msg.buf + buf_len;
 	for (i = 0, p = msg.buf; i < cpus; i++, p++) {
 		if (p >= buf_end) {
 			free(ports);
@@ -555,12 +555,12 @@ int tracecmd_msg_initial_setting(struct tracecmd_msg_handle *msg_handle)
 	if (buf_len == 0)
 		goto no_options;
 
-	if (((char *)msg.buf)[buf_len-1] != '\0') {
+	if (msg.buf[buf_len-1] != '\0') {
 		ret = -EINVAL;
 		goto error;
 	}
 
-	buf_end = (char *)msg.buf + buf_len;
+	buf_end = msg.buf + buf_len;
 	options = ntohl(msg.tinit.opt_num);
 	for (i = 0, p = msg.buf; i < options; i++, p++) {
 		if (p >= buf_end) {
-- 
2.19.1


             reply	other threads:[~2019-03-22 16:26 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-22 16:26 Slavomir Kaslev [this message]
  -- strict thread matches above, loose matches on Subject: below --
2019-03-22 15:01 [PATCH] trace-cmd: Change tracecmd_msg's buf member type to char * Slavomir Kaslev
2019-03-22 15:25 ` Steven Rostedt
2019-03-22 15:39   ` Slavomir Kaslev
2019-03-22 16:14     ` Steven Rostedt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190322162635.30689-1-kaslevs@vmware.com \
    --to=kaslevs@vmware.com \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=slavomir.kaslev@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).