shithub: choc

Download patch

ref: 1990930eb1cae6e60296ba6c85a946b063624f48
parent: 6c24da0dad1477fb0585eefac19349dd60f37c3f
author: Simon Howard <[email protected]>
date: Sat Mar 29 17:58:47 EDT 2014

common: Eliminate use of unsafe string functions.

Remove some remaining uses of strncpy() and use M_StringCopy() instead.

--- a/src/net_server.c
+++ b/src/net_server.c
@@ -32,8 +32,8 @@
 #include "d_mode.h"
 #include "i_system.h"
 #include "i_timer.h"
-
 #include "m_argv.h"
+#include "m_misc.h"
 
 #include "net_client.h"
 #include "net_common.h"
@@ -427,15 +427,12 @@
 
     for (i = 0; i < wait_data.num_players; ++i)
     {
-        strncpy(wait_data.player_names[i],
-                sv_players[i]->name,
-                MAXPLAYERNAME);
-        wait_data.player_names[i][MAXPLAYERNAME-1] = '\0';
-
-        strncpy(wait_data.player_addrs[i],
-                NET_AddrToString(sv_players[i]->addr),
-                MAXPLAYERNAME);
-        wait_data.player_addrs[i][MAXPLAYERNAME-1] = '\0';
+        M_StringCopy(wait_data.player_names[i],
+                     sv_players[i]->name,
+                     MAXPLAYERNAME);
+        M_StringCopy(wait_data.player_addrs[i],
+                     NET_AddrToString(sv_players[i]->addr),
+                     MAXPLAYERNAME);
     }
 
     // Construct packet:
--- a/src/w_checksum.c
+++ b/src/w_checksum.c
@@ -27,6 +27,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "m_misc.h"
 #include "sha1.h"
 #include "w_checksum.h"
 #include "w_wad.h"
@@ -64,8 +65,7 @@
 {
     char buf[9];
 
-    strncpy(buf, lump->name, 8);
-    buf[8] = '\0';
+    M_StringCopy(buf, lump->name, sizeof(buf));
     SHA1_UpdateString(sha1_context, buf);
     SHA1_UpdateInt32(sha1_context, GetFileNumber(lump->wad_file));
     SHA1_UpdateInt32(sha1_context, lump->position);