@@ -21,8 +21,8 @@ class AppleMIDIParser
2121 {
2222 conversionBuffer cb;
2323
24- byte signature[2 ]; // Signature "Magic Value" for Apple network MIDI session establishment
25- byte command[2 ]; // 16-bit command identifier (two ASCII characters, first in high 8 bits, second in low 8 bits)
24+ uint8_t signature[2 ]; // Signature "Magic Value" for Apple network MIDI session establishment
25+ uint8_t command[2 ]; // 16-bit command identifier (two ASCII characters, first in high 8 bits, second in low 8 bits)
2626
2727 size_t minimumLen = (sizeof (signature) + sizeof (command)); // Signature + Command
2828 if (buffer.size () < minimumLen)
@@ -42,7 +42,7 @@ class AppleMIDIParser
4242
4343 if (0 == memcmp (command, amInvitation, sizeof (amInvitation)))
4444 {
45- byte protocolVersion[4 ];
45+ uint8_t protocolVersion[4 ];
4646
4747 minimumLen += (sizeof (protocolVersion) + sizeof (initiatorToken_t) + sizeof (ssrc_t ));
4848 if (buffer.size () < minimumLen)
@@ -98,19 +98,22 @@ class AppleMIDIParser
9898 // flush the remainder of the packet.
9999 // First part if the session name is kept, processing continues
100100 if (i > minimumLen)
101- if (i == buffer.size () && buffer[i ] != 0x00 )
101+ if (i == buffer.size () && buffer[buffer. size () - 1 ] != 0x00 )
102102 retVal = parserReturn::SessionNameVeryLong;
103103
104- while (i--)
104+ while (i > 0 )
105+ {
105106 buffer.pop_front (); // consume all the bytes that made up this message
107+ --i;
108+ }
106109
107110 session->ReceivedInvitation (invitation, portType);
108111
109112 return retVal;
110113 }
111114 else if (0 == memcmp (command, amEndSession, sizeof (amEndSession)))
112115 {
113- byte protocolVersion[4 ];
116+ uint8_t protocolVersion[4 ];
114117
115118 minimumLen += (sizeof (protocolVersion) + sizeof (initiatorToken_t) + sizeof (ssrc_t ));
116119 if (buffer.size () < minimumLen)
@@ -142,8 +145,11 @@ class AppleMIDIParser
142145 cb.buffer [3 ] = buffer[i++];
143146 endSession.ssrc = __ntohl (cb.value32 );
144147
145- while (i--)
148+ while (i > 0 )
149+ {
146150 buffer.pop_front (); // consume all the bytes that made up this message
151+ --i;
152+ }
147153
148154 session->ReceivedEndSession (endSession);
149155
@@ -199,8 +205,11 @@ class AppleMIDIParser
199205 cb.buffer [7 ] = buffer[i++];
200206 synchronization.timestamps [2 ] = __ntohll (cb.value64 );
201207
202- while (i--)
208+ while (i > 0 )
209+ {
203210 buffer.pop_front (); // consume all the bytes that made up this message
211+ --i;
212+ }
204213
205214 session->ReceivedSynchronization (synchronization);
206215
@@ -237,7 +246,7 @@ class AppleMIDIParser
237246#ifdef APPLEMIDI_INITIATOR
238247 else if (0 == memcmp (command, amInvitationAccepted, sizeof (amInvitationAccepted)))
239248 {
240- byte protocolVersion[4 ];
249+ uint8_t protocolVersion[4 ];
241250
242251 minimumLen += (sizeof (protocolVersion) + sizeof (initiatorToken_t) + sizeof (ssrc_t ));
243252 if (buffer.size () < minimumLen)
@@ -294,19 +303,22 @@ class AppleMIDIParser
294303 // flush the remainder of the packet.
295304 // First part if the session name is kept, processing continues
296305 if (i > minimumLen)
297- if (i == buffer.size () && buffer[i ] != 0x00 )
306+ if (i == buffer.size () && buffer[buffer. size () - 1 ] != 0x00 )
298307 retVal = parserReturn::SessionNameVeryLong;
299308
300- while (i--)
309+ while (i > 0 )
310+ {
301311 buffer.pop_front (); // consume all the bytes that made up this message
312+ --i;
313+ }
302314
303315 session->ReceivedInvitationAccepted (invitationAccepted, portType);
304316
305317 return retVal;
306318 }
307319 else if (0 == memcmp (command, amInvitationRejected, sizeof (amInvitationRejected)))
308320 {
309- byte protocolVersion[4 ];
321+ uint8_t protocolVersion[4 ];
310322
311323 minimumLen += (sizeof (protocolVersion) + sizeof (initiatorToken_t) + sizeof (ssrc_t ));
312324 if (buffer.size () < minimumLen)
@@ -359,8 +371,11 @@ class AppleMIDIParser
359371 if (i == buffer.size () || buffer[i++] != 0x00 )
360372 return parserReturn::NotEnoughData;
361373
362- while (i--)
374+ while (i > 0 )
375+ {
363376 buffer.pop_front (); // consume all the bytes that made up this message
377+ --i;
378+ }
364379
365380 session->ReceivedInvitationRejected (invitationRejected);
366381
@@ -386,8 +401,11 @@ class AppleMIDIParser
386401 cb.buffer [3 ] = buffer[i++];
387402 bitrateReceiveLimit.bitratelimit = __ntohl (cb.value32 );
388403
389- while (i--)
404+ while (i > 0 )
405+ {
390406 buffer.pop_front (); // consume all the bytes that made up this message
407+ --i;
408+ }
391409
392410 session->ReceivedBitrateReceiveLimit (bitrateReceiveLimit);
393411
0 commit comments