summaryrefslogtreecommitdiff
path: root/src/net.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/net.c')
-rw-r--r--src/net.c24
1 files changed, 22 insertions, 2 deletions
diff --git a/src/net.c b/src/net.c
index 0567179..1b3811d 100644
--- a/src/net.c
+++ b/src/net.c
@@ -84,7 +84,11 @@ int* server_get_players(int serversock, const uint8_t count)
assert(count < MAX_PLAYERS && count > 0);
clientsocks = malloc(count*sizeof(int));
- assert(clientsocks != NULL);
+ if(clientsocks == NULL)
+ {
+ printf("server_get_players: Out of memory\n");
+ exit(EXIT_FAILURE);
+ }
// accept connections
for(i=0; i<count; i++)
@@ -117,6 +121,11 @@ void client_hello(int sock, const char* username)
uint8_t namelen = strlen(username);
buf = malloc(namelen+2); // type + len + username
+ if(buf == NULL)
+ {
+ printf("client_hello: Out of memory\n");
+ exit(EXIT_FAILURE);
+ }
buf[0] = msg_type_hello;
buf[1] = namelen;
@@ -187,6 +196,11 @@ void server_start_game(int* clients, const uint8_t clientcount, const char* user
buflen += strlen(usernames[i]);
buf = malloc(buflen);
+ if(buf == NULL)
+ {
+ printf("server_start_game: Out of memory\n");
+ exit(EXIT_FAILURE);
+ }
buf[pos++] = msg_type_start_game;
buf[pos++] = clientcount;
// copy usernames with length to buffer
@@ -221,7 +235,13 @@ char* server_recv_hello(int sock)
namelen = buf[1];
name = malloc(namelen+1);
- strncpy(name, buf+2, namelen);
+ if(name == NULL)
+ {
+ printf("sender_recv_hello: Out of memory\n");
+ exit(EXIT_FAILURE);
+ }
+
+ memcpy(name, buf+2, namelen);
name[namelen] = '\0';
return name;