Changeset View
Changeset View
Standalone View
Standalone View
source/network/StunClient.cpp
Show First 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
if (offset + n > buffer.size()) | if (offset + n > buffer.size()) | ||||
return false; | return false; | ||||
int a = n; | int a = n; | ||||
offset += n; | offset += n; | ||||
while (a--) | while (a--) | ||||
{ | { | ||||
// Prevent shift count overflow if the type is u8 | |||||
if (n > 1) | |||||
result <<= 8; | result <<= 8; | ||||
result += buffer[offset - 1 - a]; | result += buffer[offset - 1 - a]; | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
/** | /** | ||||
leper: I guess one could provide a specialization of the other function so someone calling that with… | |||||
Not Done Inline ActionsSince n is a deduced argument, it could only be template<u8> bool GetFromBuffer(const std::vector<u8>& buffer, u32& offset, u8& result) But then I still have the clang compile warning. Since this function copies one line, we can just keep that one function and add that n=1 special case to that function if we can't resolve the specialization however. I believe it might be possible to do something with template constraints http://en.cppreference.com/w/cpp/language/constraints (search for size on that page), but that looks alien and might even end up more complicated and longer. elexis: Since `n` is a deduced argument, it could only be
```
template<u8>
bool GetFromBuffer(const std… | |||||
* Creates a STUN request and sends it to a STUN server. | * Creates a STUN request and sends it to a STUN server. | ||||
* The request is sent through transactionHost, from which the answer | * The request is sent through transactionHost, from which the answer | ||||
* will be retrieved by ReceiveStunResponse and interpreted by ParseStunResponse. | * will be retrieved by ReceiveStunResponse and interpreted by ParseStunResponse. | ||||
*/ | */ | ||||
bool CreateStunRequest(ENetHost* transactionHost) | bool CreateStunRequest(ENetHost* transactionHost) | ||||
{ | { | ||||
ENSURE(transactionHost); | ENSURE(transactionHost); | ||||
▲ Show 20 Lines • Show All 298 Lines • Show Last 20 Lines |
Wildfire Games · Phabricator
I guess one could provide a specialization of the other function so someone calling that with u8 does not run into the same issue again.