check packet size by static_assert#2830
Conversation
|
What would happen if it becomes too large? |
There was a problem hiding this comment.
Pull Request Overview
This PR replaces the runtime packet-size guard in two send functions with a compile-time assertion to enforce size limits.
- Replace
if (sizeof(ST) > MAX_DATA_SIZE) return;checks withstatic_assertin bothSendPacketToPlayerandSendPacketToServer. - Enforce packet payload size at compile time rather than silently dropping oversized packets.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| gframe/netserver.h | Swapped runtime check for packet size with a compile-time static_assert. |
| gframe/duelclient.h | Swapped runtime check for packet size with a compile-time static_assert. |
Comments suppressed due to low confidence (2)
gframe/netserver.h:46
- Add a brief comment above this
static_assertto explain that it replaces the old runtime guard to enforce packet-size limits at compile time and avoid silent drops.
static_assert(sizeof(ST) <= MAX_DATA_SIZE, "Packet size is too large.");
gframe/duelclient.h:58
- Add a brief comment above this
static_assertto explain that it replaces the old runtime guard to enforce packet-size limits at compile time and avoid silent drops.
static_assert(sizeof(ST) <= MAX_DATA_SIZE, "Packet size is too large.");
You will get an error like:
So you cannot compile. static_assert(sizeof(ST) > MAX_DATA_SIZE, "Packet size is too large.");MAX_DATA_SIZE is 65534 now. |
No description provided.