diff options
author | yhirano <yhirano@chromium.org> | 2014-11-03 18:58:10 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2014-11-04 02:58:27 +0000 |
commit | 84beeaa373ad30771120f533dc8d2c8f14524654 (patch) | |
tree | 221a4499dc7e4817367c2ef29418f7e59ffac095 /media | |
parent | 4d54576d6bc28518e853791c8b1a05813f72cb50 (diff) | |
download | chromium_src-84beeaa373ad30771120f533dc8d2c8f14524654.zip chromium_src-84beeaa373ad30771120f533dc8d2c8f14524654.tar.gz chromium_src-84beeaa373ad30771120f533dc8d2c8f14524654.tar.bz2 |
[WebMIDI] Fix code style to suppress a static analysis error.
A static code analyzer reports an error in usb_midi_output_stream.cc, which
is a message_size_table buffer overflow. This CL fixes the code.
Note that the reported error never happens and hence the fix doesn't change
the behavior.
BUG=427616
Review URL: https://codereview.chromium.org/694733002
Cr-Commit-Position: refs/heads/master@{#302560}
Diffstat (limited to 'media')
-rw-r--r-- | media/midi/usb_midi_output_stream.cc | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/media/midi/usb_midi_output_stream.cc b/media/midi/usb_midi_output_stream.cc index 1aef282..2f32897 100644 --- a/media/midi/usb_midi_output_stream.cc +++ b/media/midi/usb_midi_output_stream.cc @@ -121,10 +121,12 @@ bool UsbMidiOutputStream::PushSysCommonMessage( uint8 first_byte = Get(data, index); DCHECK_LE(0xf1, first_byte); DCHECK_LE(first_byte, 0xf7); + DCHECK_EQ(0xf0, first_byte & 0xf8); + // There are only 6 message types (0xf1 - 0xf7), so the table size is 8. const size_t message_size_table[8] = { 0, 2, 3, 2, 1, 1, 1, 0, }; - size_t message_size = message_size_table[first_byte & 0x0f]; + size_t message_size = message_size_table[first_byte & 0x07]; DCHECK_NE(0u, message_size); DCHECK_LE(message_size, 3u); @@ -161,13 +163,17 @@ bool UsbMidiOutputStream::PushChannelMessage(const std::vector<uint8>& data, std::vector<uint8>* data_to_send) { size_t index = *current; uint8 first_byte = Get(data, index); + DCHECK_LE(0x80, (first_byte & 0xf0)); DCHECK_LE((first_byte & 0xf0), 0xe0); - + // There are only 7 message types (0x8-0xe in the higher four bits), so the + // table size is 8. const size_t message_size_table[8] = { 3, 3, 3, 3, 2, 3, 3, 0, }; uint8 code_index = first_byte >> 4; + DCHECK_LE(0x08, code_index); + DCHECK_LE(code_index, 0x0e); size_t message_size = message_size_table[code_index & 0x7]; DCHECK_NE(0u, message_size); DCHECK_LE(message_size, 3u); |