fix serious but rare error in RTMidiBuffer's storage of MIDI events with size > 3
authorPaul Davis <paul@linuxaudiosystems.com>
Tue, 7 Jan 2020 21:10:14 +0000 (14:10 -0700)
committerPaul Davis <paul@linuxaudiosystems.com>
Wed, 8 Jan 2020 02:27:04 +0000 (19:27 -0700)
sizeof (T) is in units of bytes, not bits. Use C++ standard CHAR_BITS instead.

libs/ardour/rt_midibuffer.cc

index e2490c23c23b3f1b54e3e91be32ee7f9ee4f4524..6227b77b2d2870b198e647ad5e7791c0a0b3452e 100644 (file)
@@ -165,7 +165,7 @@ RTMidiBuffer::dump (uint32_t cnt)
 
                        /* more than 3 bytes ... indirect */
 
-                       uint32_t offset = item->offset & ~(1<<(sizeof(uint8_t)-1));
+                       uint32_t offset = item->offset & ~(1<<(CHAR_BIT-1));
                        Blob* blob = reinterpret_cast<Blob*> (&_pool[offset]);
 
                        size = blob->size;
@@ -205,7 +205,7 @@ RTMidiBuffer::write (TimeType time, Evoral::EventType /*type*/, uint32_t size, c
                uint32_t off = store_blob (size, buf);
 
                /* non-zero MSbit indicates that the data (more than 3 bytes) is not inline */
-               _data[_size].offset = (off | (1<<(sizeof(uint8_t)-1)));
+               _data[_size].offset = (off | (1<<(CHAR_BIT-1)));
 
        } else {
 
@@ -312,7 +312,7 @@ RTMidiBuffer::read (MidiBuffer& dst, samplepos_t start, samplepos_t end, MidiSta
 
                        /* more than 3 bytes ... indirect */
 
-                       uint32_t offset = item->offset & ~(1<<(sizeof(uint8_t)-1));
+                       uint32_t offset = item->offset & ~(1<<(CHAR_BIT-1));
                        Blob* blob = reinterpret_cast<Blob*> (&_pool[offset]);
 
                        size = blob->size;