summaryrefslogtreecommitdiff
path: root/src/network
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2014-04-23 21:12:09 +0000
committerrubidium <rubidium@openttd.org>2014-04-23 21:12:09 +0000
commit5b82822c12e014771dceaf9d909e1c0f3653c5a9 (patch)
tree1cf02e076eb61eb94d9064c7cb02bbe85ecb9a6c /src/network
parentef4c2ce0317ae583e837722b6a41ea44cd83da71 (diff)
downloadopenttd-5b82822c12e014771dceaf9d909e1c0f3653c5a9.tar.xz
(svn r26486) -Codechange: replace a number of snprintfs with seprintf
Diffstat (limited to 'src/network')
-rw-r--r--src/network/network.cpp13
-rw-r--r--src/network/network_chat_gui.cpp2
-rw-r--r--src/network/network_client.cpp4
-rw-r--r--src/network/network_gui.cpp2
-rw-r--r--src/network/network_udp.cpp2
5 files changed, 11 insertions, 12 deletions
diff --git a/src/network/network.cpp b/src/network/network.cpp
index c22615a95..5eefb850d 100644
--- a/src/network/network.cpp
+++ b/src/network/network.cpp
@@ -199,7 +199,7 @@ const char *GenerateCompanyPasswordHash(const char *password, const char *passwo
char salted_password[NETWORK_SERVER_ID_LENGTH];
memset(salted_password, 0, sizeof(salted_password));
- snprintf(salted_password, sizeof(salted_password), "%s", password);
+ seprintf(salted_password, lastof(salted_password), "%s", password);
/* Add the game seed and the server's ID as the salt. */
for (uint i = 0; i < NETWORK_SERVER_ID_LENGTH - 1; i++) {
salted_password[i] ^= password_server_id[i] ^ (password_game_seed >> (i % 32));
@@ -213,8 +213,7 @@ const char *GenerateCompanyPasswordHash(const char *password, const char *passwo
checksum.Append(salted_password, sizeof(salted_password) - 1);
checksum.Finish(digest);
- for (int di = 0; di < 16; di++) sprintf(hashed_password + di * 2, "%02x", digest[di]);
- hashed_password[lengthof(hashed_password) - 1] = '\0';
+ for (int di = 0; di < 16; di++) seprintf(hashed_password + di * 2, lastof(hashed_password), "%02x", digest[di]);
return hashed_password;
}
@@ -703,7 +702,7 @@ void NetworkClientConnectGame(NetworkAddress address, CompanyID join_as, const c
static void NetworkInitGameInfo()
{
if (StrEmpty(_settings_client.network.server_name)) {
- snprintf(_settings_client.network.server_name, sizeof(_settings_client.network.server_name), "Unnamed Server");
+ seprintf(_settings_client.network.server_name, lastof(_settings_client.network.server_name), "Unnamed Server");
}
/* The server is a client too */
@@ -1028,18 +1027,18 @@ static void NetworkGenerateServerId()
char coding_string[NETWORK_NAME_LENGTH];
int di;
- snprintf(coding_string, sizeof(coding_string), "%d%s", (uint)Random(), "OpenTTD Server ID");
+ seprintf(coding_string, lastof(coding_string), "%d%s", (uint)Random(), "OpenTTD Server ID");
/* Generate the MD5 hash */
checksum.Append((const uint8*)coding_string, strlen(coding_string));
checksum.Finish(digest);
for (di = 0; di < 16; ++di) {
- sprintf(hex_output + di * 2, "%02x", digest[di]);
+ seprintf(hex_output + di * 2, lastof(hex_output), "%02x", digest[di]);
}
/* _settings_client.network.network_id is our id */
- snprintf(_settings_client.network.network_id, sizeof(_settings_client.network.network_id), "%s", hex_output);
+ seprintf(_settings_client.network.network_id, lastof(_settings_client.network.network_id), "%s", hex_output);
}
void NetworkStartDebugLog(NetworkAddress address)
diff --git a/src/network/network_chat_gui.cpp b/src/network/network_chat_gui.cpp
index 2a06082dd..f8a0867f3 100644
--- a/src/network/network_chat_gui.cpp
+++ b/src/network/network_chat_gui.cpp
@@ -428,7 +428,7 @@ struct NetworkChatWindow : public Window {
len = strlen(cur_name);
if (tb_len < len && strncasecmp(cur_name, tb_buf, tb_len) == 0) {
/* Save the data it was before completion */
- if (!second_scan) snprintf(_chat_tab_completion_buf, lengthof(_chat_tab_completion_buf), "%s", tb->buf);
+ if (!second_scan) seprintf(_chat_tab_completion_buf, lastof(_chat_tab_completion_buf), "%s", tb->buf);
_chat_tab_completion_active = true;
/* Change to the found name. Add ': ' if we are at the start of the line (pretty) */
diff --git a/src/network/network_client.cpp b/src/network/network_client.cpp
index 10e3695b7..8098c00c2 100644
--- a/src/network/network_client.cpp
+++ b/src/network/network_client.cpp
@@ -958,7 +958,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(Packet *p)
switch (action) {
case NETWORK_ACTION_CHAT_CLIENT:
/* For speaking to client we need the client-name */
- snprintf(name, sizeof(name), "%s", ci_to->client_name);
+ seprintf(name, lastof(name), "%s", ci_to->client_name);
ci = NetworkClientInfo::GetByClientID(_network_own_client_id);
break;
@@ -979,7 +979,7 @@ NetworkRecvStatus ClientNetworkGameSocketHandler::Receive_SERVER_CHAT(Packet *p)
}
} else {
/* Display message from somebody else */
- snprintf(name, sizeof(name), "%s", ci_to->client_name);
+ seprintf(name, lastof(name), "%s", ci_to->client_name);
ci = ci_to;
}
diff --git a/src/network/network_gui.cpp b/src/network/network_gui.cpp
index 09c2623e7..0580dc95c 100644
--- a/src/network/network_gui.cpp
+++ b/src/network/network_gui.cpp
@@ -756,7 +756,7 @@ public:
case WID_NG_JOIN: // Join Game
if (this->server != NULL) {
- snprintf(_settings_client.network.last_host, sizeof(_settings_client.network.last_host), "%s", this->server->address.GetHostname());
+ seprintf(_settings_client.network.last_host, lastof(_settings_client.network.last_host), "%s", this->server->address.GetHostname());
_settings_client.network.last_port = this->server->address.GetPort();
ShowNetworkLobbyWindow(this->server);
}
diff --git a/src/network/network_udp.cpp b/src/network/network_udp.cpp
index 46d8fddef..731d51ca0 100644
--- a/src/network/network_udp.cpp
+++ b/src/network/network_udp.cpp
@@ -384,7 +384,7 @@ void ClientNetworkUDPSocketHandler::Receive_SERVER_RESPONSE(Packet *p, NetworkAd
}
if (item->info.hostname[0] == '\0') {
- snprintf(item->info.hostname, sizeof(item->info.hostname), "%s", client_addr->GetHostname());
+ seprintf(item->info.hostname, lastof(item->info.hostname), "%s", client_addr->GetHostname());
}
if (client_addr->GetAddress()->ss_family == AF_INET6) {