|
133 | 133 |
|
134 | 134 | enum EDualWifiEnable { |
135 | 135 | k_nDualWifiEnable_Disable = 0, |
136 | | - k_nDualWifiEnable_Enable = 1, // |
| 136 | + k_nDualWifiEnable_Enable = 1, // |
137 | 137 | k_nDualWifiEnable_DoNotEnumerate = 2, // Enumerate primary adapters, but don't actually try to enable any Dual Wifi support |
138 | 138 | k_nDualWifiEnable_DoNotBind = 3, // Try to turn on Dual Wifi and locate the secondary adapter, but don't actually bind |
139 | 139 | k_nDualWifiEnable_ForceSimulate = 4, // Don't really do any DualWifi work, just open up another "regular" socket |
@@ -370,7 +370,7 @@ const uint32 k_nCurrentProtocolVersion = 12; |
370 | 370 | /// when we introduce wire breaking protocol changes and do not wish to be |
371 | 371 | /// backward compatible. This has been fine before the first major release, |
372 | 372 | /// but once we make a big public release, we probably won't ever be able to |
373 | | -/// do this again, and we'll need to have more sophisticated mechanisms. |
| 373 | +/// do this again, and we'll need to have more sophisticated mechanisms. |
374 | 374 | const uint32 k_nMinRequiredProtocolVersion = 8; |
375 | 375 |
|
376 | 376 | /// SteamNetworkingMessages is built on top of SteamNetworkingSockets. We use a reserved |
@@ -469,19 +469,21 @@ inline int VarIntSerializedSize( uint64 x ) |
469 | 469 |
|
470 | 470 | // De-serialize a var-int encoded quantity. Returns pointer to the next byte, |
471 | 471 | // or NULL if there was a decoding error (we hit the end of stream.) |
472 | | -// https://developers.google.com/protocol-buffers/docs/encoding |
473 | | -// |
474 | | -// NOTE: We do not detect overflow. |
| 472 | +// https://developers.google.com/protocol-buffers/docs/encoding/ |
475 | 473 | template <typename T> |
476 | 474 | inline byte *DeserializeVarInt( byte *p, const byte *end, T &x ) |
477 | 475 | { |
478 | | - if ( p >= end ) |
| 476 | + if ( unlikely( p >= end ) ) |
479 | 477 | return nullptr; |
| 478 | + const byte *max_end = p + ( (sizeof(T)*8 + 6) / 7 ); |
| 479 | + if ( end > max_end ) |
| 480 | + end = max_end; |
| 481 | + |
480 | 482 | T nResult = *p & 0x7f; // use local variable for working, to make sure compiler doesn't try to worry about pointer aliasing |
481 | 483 | unsigned nShift = 7; |
482 | 484 | while ( *(p++) & 0x80 ) |
483 | 485 | { |
484 | | - if ( p >= end ) |
| 486 | + if ( unlikely( p >= end ) ) |
485 | 487 | return nullptr; |
486 | 488 | nResult |= ( T( *p & 0x7f ) << nShift ); |
487 | 489 | nShift += 7; |
@@ -1611,7 +1613,7 @@ namespace vstd |
1611 | 1613 | { |
1612 | 1614 | // We need dynamic memory. If we're not exactly sized already, |
1613 | 1615 | // just nuke everyhing we have. |
1614 | | - if ( n != capacity_ ) |
| 1616 | + if ( n != capacity_ ) |
1615 | 1617 | { |
1616 | 1618 | clear(); |
1617 | 1619 | reserve( n ); |
|
0 commit comments