Skip to content

Commit e715bd0

Browse files
authored
check packet size by static_assert (#2830)
1 parent 081b7e9 commit e715bd0

2 files changed

Lines changed: 2 additions & 4 deletions

File tree

gframe/duelclient.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,7 @@ class DuelClient {
5555
template<typename ST>
5656
static void SendPacketToServer(unsigned char proto, const ST& st) {
5757
auto p = duel_client_write;
58-
if (sizeof(ST) > MAX_DATA_SIZE)
59-
return;
58+
static_assert(sizeof(ST) <= MAX_DATA_SIZE, "Packet size is too large.");
6059
buffer_write<uint16_t>(p, (uint16_t)(1 + sizeof(ST)));
6160
buffer_write<uint8_t>(p, proto);
6261
std::memcpy(p, &st, sizeof(ST));

gframe/netserver.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,7 @@ class NetServer {
4343
template<typename ST>
4444
static void SendPacketToPlayer(DuelPlayer* dp, unsigned char proto, const ST& st) {
4545
auto p = net_server_write;
46-
if (sizeof(ST) > MAX_DATA_SIZE)
47-
return;
46+
static_assert(sizeof(ST) <= MAX_DATA_SIZE, "Packet size is too large.");
4847
buffer_write<uint16_t>(p, (uint16_t)(1 + sizeof(ST)));
4948
buffer_write<uint8_t>(p, proto);
5049
std::memcpy(p, &st, sizeof(ST));

0 commit comments

Comments
 (0)