All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Felipe F. Tonello" <eu@felipetonello.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ 1/2] profiles/midi: Add safer buffer setter function
Date: Tue,  7 Feb 2017 23:40:42 +0000	[thread overview]
Message-ID: <20170207234043.14003-2-eu@felipetonello.com> (raw)
In-Reply-To: <20170207234043.14003-1-eu@felipetonello.com>

This function helper makes buffer operations more consistent and adds
boundary check when its available.

Signed-off-by: Felipe F. Tonello <eu@felipetonello.com>
---
 profiles/midi/libmidi.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/profiles/midi/libmidi.c b/profiles/midi/libmidi.c
index ac090b59eb60..4b4df799fc2e 100644
--- a/profiles/midi/libmidi.c
+++ b/profiles/midi/libmidi.c
@@ -52,6 +52,13 @@ inline static uint8_t buffer_reverse_get(struct midi_buffer *buffer, size_t i)
 	return buffer->data[buffer->len - (i + 1)];
 }
 
+inline static void buffer_reverse_set(struct midi_buffer *buffer, size_t i,
+                                      const uint8_t byte)
+{
+	MIDI_ASSERT(buffer->len > i);
+	buffer->data[buffer->len - (i + 1)] = byte;
+}
+
 inline static size_t parser_get_available_size(struct midi_write_parser *parser)
 {
 	return parser->stream_size - parser->midi_stream.len;
@@ -314,7 +321,7 @@ static size_t handle_end_of_sysex(struct midi_read_parser *parser,
 	time_low = buffer_reverse_get(&parser->sysex_stream, 0) & 0x7F;
 
 	/* Remove timestamp byte */
-	parser->sysex_stream.data[parser->sysex_stream.len - 1] = 0xF7;
+	buffer_reverse_set(&parser->sysex_stream, 0, 0xF7);
 
 	/* Update event */
 	update_ev_timestamp(parser, ev, time_low);
-- 
2.11.0


  reply	other threads:[~2017-02-07 23:40 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-07 23:40 [PATCH BlueZ 0/2] Minor MIDI profile improvements Felipe F. Tonello
2017-02-07 23:40 ` Felipe F. Tonello [this message]
2017-02-08 12:45   ` [PATCH BlueZ 1/2] profiles/midi: Add safer buffer setter function Luiz Augusto von Dentz
2017-02-09 14:46     ` Felipe Ferreri Tonello
2017-02-07 23:40 ` [PATCH BlueZ 2/2] profiles/midi: Moved MIDI UUIDs to library header Felipe F. Tonello

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=20170207234043.14003-2-eu@felipetonello.com \
    --to=eu@felipetonello.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.