commit 2855c1081facf4812cc74a48c880bc8832b0ede1
Author: Simon Howard <fraggle@soulsphere.org>
AuthorDate: Thu Sep 28 08:48:23 2017 -0400
Commit: Simon Howard <fraggle@soulsphere.org>
CommitDate: Thu Sep 28 08:48:23 2017 -0400
net: Make a bunch of things const.
@turol pointed out in #943 that these should be marked as const. This
requires fixing `NET_WriteString()` but is the right thing to do
nonetheless.
---
src/net_common.c | 10 ++++++----
src/net_packet.c | 2 +-
src/net_packet.h | 2 +-
3 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/src/net_common.c b/src/net_common.c
index fb7bca77..aad6daa4 100644
--- a/src/net_common.c
+++ b/src/net_common.c
@@ -35,10 +35,12 @@
#define KEEPALIVE_PERIOD 1
+// String names for the enum values in net_protocol_t, which are what is
+// sent over the wire. Every enum value must have an entry in this list.
static struct
{
net_protocol_t protocol;
- char *name;
+ const char *name;
} protocol_names[] = {
{NET_PROTOCOL_CHOCOLATE_DOOM_0, "CHOCOLATE_DOOM_0"},
};
@@ -480,7 +482,7 @@ boolean NET_ValidGameSettings(GameMode_t mode, GameMission_t mission,
return true;
}
-static net_protocol_t ParseProtocolName(char *name)
+static net_protocol_t ParseProtocolName(const char *name)
{
int i;
@@ -500,7 +502,7 @@ static net_protocol_t ParseProtocolName(char *name)
// protocol.
net_protocol_t NET_ReadProtocol(net_packet_t *packet)
{
- char *name;
+ const char *name;
name = NET_ReadString(packet);
if (name == NULL)
@@ -551,7 +553,7 @@ net_protocol_t NET_ReadProtocolList(net_packet_t *packet)
for (i = 0; i < num_protocols; ++i)
{
net_protocol_t p;
- char *name;
+ const char *name;
name = NET_ReadString(packet);
if (name == NULL)
diff --git a/src/net_packet.c b/src/net_packet.c
index ae1be7cb..aa187f8d 100644
--- a/src/net_packet.c
+++ b/src/net_packet.c
@@ -302,7 +302,7 @@ void NET_WriteInt32(net_packet_t *packet, unsigned int i)
packet->len += 4;
}
-void NET_WriteString(net_packet_t *packet, char *string)
+void NET_WriteString(net_packet_t *packet, const char *string)
{
byte *p;
size_t string_size;
diff --git a/src/net_packet.h b/src/net_packet.h
index 011f1af9..6beb44b2 100644
--- a/src/net_packet.h
+++ b/src/net_packet.h
@@ -39,7 +39,7 @@ void NET_WriteInt8(net_packet_t *packet, unsigned int i);
void NET_WriteInt16(net_packet_t *packet, unsigned int i);
void NET_WriteInt32(net_packet_t *packet, unsigned int i);
-void NET_WriteString(net_packet_t *packet, char *string);
+void NET_WriteString(net_packet_t *packet, const char *string);
#endif /* #ifndef NET_PACKET_H */