1
0
mirror of https://github.com/OpenTTD/OpenTTD.git synced 2025-08-19 12:39:11 +00:00

(svn r26486) -Codechange: replace a number of snprintfs with seprintf

This commit is contained in:
rubidium
2014-04-23 21:12:09 +00:00
parent ef4c2ce031
commit 5b82822c12
26 changed files with 61 additions and 59 deletions

View File

@@ -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)

View File

@@ -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) */

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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) {