mirror of https://github.com/OpenTTD/OpenTTD
Codechange: use value initialisation over memset
parent
7981fcb297
commit
f8aceb6c37
|
@ -18,5 +18,5 @@ Cheats _cheats;
|
|||
/** Reinitialise all the cheats. */
|
||||
void InitializeCheats()
|
||||
{
|
||||
memset(&_cheats, 0, sizeof(Cheats));
|
||||
_cheats = {};
|
||||
}
|
||||
|
|
|
@ -14,8 +14,8 @@
|
|||
* Info about each of the cheats.
|
||||
*/
|
||||
struct Cheat {
|
||||
bool been_used; ///< has this cheat been used before?
|
||||
bool value; ///< tells if the bool cheat is active or not
|
||||
bool been_used = false; ///< has this cheat been used before?
|
||||
bool value = false; ///< tells if the bool cheat is active or not
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -24,15 +24,15 @@ struct Cheat {
|
|||
* Only add new entries at the end of the struct!
|
||||
*/
|
||||
struct Cheats {
|
||||
Cheat magic_bulldozer; ///< dynamite industries, objects
|
||||
Cheat switch_company; ///< change to another company
|
||||
Cheat money; ///< get rich or poor
|
||||
Cheat crossing_tunnels; ///< allow tunnels that cross each other
|
||||
Cheat no_jetcrash; ///< no jet will crash on small airports anymore
|
||||
Cheat change_date; ///< changes date ingame
|
||||
Cheat setup_prod; ///< setup raw-material production in game
|
||||
Cheat edit_max_hl; ///< edit the maximum heightlevel; this is a cheat because of the fact that it needs to reset NewGRF game state and doing so as a simple configuration breaks the expectation of many
|
||||
Cheat station_rating; ///< Fix station ratings at 100%
|
||||
Cheat magic_bulldozer{}; ///< dynamite industries, objects
|
||||
Cheat switch_company{}; ///< change to another company
|
||||
Cheat money{}; ///< get rich or poor
|
||||
Cheat crossing_tunnels{}; ///< allow tunnels that cross each other
|
||||
Cheat no_jetcrash{}; ///< no jet will crash on small airports anymore
|
||||
Cheat change_date{}; ///< changes date ingame
|
||||
Cheat setup_prod{}; ///< setup raw-material production in game
|
||||
Cheat edit_max_hl{}; ///< edit the maximum heightlevel; this is a cheat because of the fact that it needs to reset NewGRF game state and doing so as a simple configuration breaks the expectation of many
|
||||
Cheat station_rating{}; ///< Fix station ratings at 100%
|
||||
};
|
||||
|
||||
extern Cheats _cheats;
|
||||
|
|
|
@ -202,8 +202,7 @@ bool NetworkAddress::IsInNetmask(std::string_view netmask)
|
|||
SOCKET NetworkAddress::Resolve(int family, int socktype, int flags, SocketList *sockets, LoopProc func)
|
||||
{
|
||||
struct addrinfo *ai;
|
||||
struct addrinfo hints;
|
||||
memset(&hints, 0, sizeof (hints));
|
||||
struct addrinfo hints{};
|
||||
hints.ai_family = family;
|
||||
hints.ai_flags = flags;
|
||||
hints.ai_socktype = socktype;
|
||||
|
|
|
@ -27,10 +27,10 @@ using SocketList = std::map<SOCKET, NetworkAddress>; ///< Type for a mapping
|
|||
*/
|
||||
class NetworkAddress {
|
||||
private:
|
||||
std::string hostname; ///< The hostname
|
||||
int address_length; ///< The length of the resolved address
|
||||
sockaddr_storage address; ///< The resolved address
|
||||
bool resolved; ///< Whether the address has been (tried to be) resolved
|
||||
std::string hostname{}; ///< The hostname
|
||||
int address_length{}; ///< The length of the resolved address
|
||||
sockaddr_storage address{}; ///< The resolved address
|
||||
bool resolved = false; ///< Whether the address has been (tried to be) resolved
|
||||
|
||||
/**
|
||||
* Helper function to resolve something to a socket.
|
||||
|
@ -62,7 +62,6 @@ public:
|
|||
address_length(address_length),
|
||||
resolved(address_length != 0)
|
||||
{
|
||||
memset(&this->address, 0, sizeof(this->address));
|
||||
memcpy(&this->address, address, address_length);
|
||||
}
|
||||
|
||||
|
@ -81,8 +80,6 @@ public:
|
|||
hostname.remove_suffix(1);
|
||||
}
|
||||
this->hostname = hostname;
|
||||
|
||||
memset(&this->address, 0, sizeof(this->address));
|
||||
this->address.ss_family = family;
|
||||
this->SetPort(port);
|
||||
}
|
||||
|
|
|
@ -222,8 +222,7 @@ void TCPConnecter::Resolve()
|
|||
/* Port is already guaranteed part of the connection_string. */
|
||||
NetworkAddress address = ParseConnectionString(this->connection_string, 0);
|
||||
|
||||
addrinfo hints;
|
||||
memset(&hints, 0, sizeof(hints));
|
||||
addrinfo hints{};
|
||||
hints.ai_family = AF_UNSPEC;
|
||||
hints.ai_flags = AI_ADDRCONFIG;
|
||||
hints.ai_socktype = SOCK_STREAM;
|
||||
|
|
|
@ -76,8 +76,7 @@ public:
|
|||
static void AcceptClient(SOCKET ls)
|
||||
{
|
||||
for (;;) {
|
||||
struct sockaddr_storage sin;
|
||||
memset(&sin, 0, sizeof(sin));
|
||||
struct sockaddr_storage sin{};
|
||||
socklen_t sin_len = sizeof(sin);
|
||||
SOCKET s = accept(ls, (struct sockaddr*)&sin, &sin_len);
|
||||
if (s == INVALID_SOCKET) return;
|
||||
|
|
|
@ -113,8 +113,7 @@ void NetworkUDPSocketHandler::ReceivePackets()
|
|||
{
|
||||
for (auto &s : this->sockets) {
|
||||
for (int i = 0; i < 1000; i++) { // Do not infinitely loop when DoSing with UDP
|
||||
struct sockaddr_storage client_addr;
|
||||
memset(&client_addr, 0, sizeof(client_addr));
|
||||
struct sockaddr_storage client_addr{};
|
||||
|
||||
/* The limit is UDP_MTU, but also allocate that much as we need to read the whole packet in one go. */
|
||||
Packet p(this, UDP_MTU, UDP_MTU);
|
||||
|
|
|
@ -159,8 +159,7 @@ static sigset_t SetSignals(void(*handler)(int))
|
|||
sigaddset(&sigs, signum);
|
||||
}
|
||||
|
||||
struct sigaction sa;
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
struct sigaction sa{};
|
||||
sa.sa_flags = SA_RESTART;
|
||||
|
||||
sigemptyset(&sa.sa_mask);
|
||||
|
|
|
@ -146,8 +146,7 @@ static sigset_t SetSignals(void(*handler)(int))
|
|||
sigaddset(&sigs, signum);
|
||||
}
|
||||
|
||||
struct sigaction sa;
|
||||
memset(&sa, 0, sizeof(sa));
|
||||
struct sigaction sa{};
|
||||
sa.sa_flags = SA_RESTART;
|
||||
|
||||
sigemptyset(&sa.sa_mask);
|
||||
|
|
|
@ -212,8 +212,7 @@ static const uint MAX_FRAMES = 64;
|
|||
proc.pSymSetOptions(SYMOPT_DEFERRED_LOADS | SYMOPT_FAIL_CRITICAL_ERRORS | SYMOPT_UNDNAME);
|
||||
|
||||
/* Initialize starting stack frame from context record. */
|
||||
STACKFRAME64 frame;
|
||||
memset(&frame, 0, sizeof(frame));
|
||||
STACKFRAME64 frame{};
|
||||
#ifdef _M_AMD64
|
||||
frame.AddrPC.Offset = ep->ContextRecord->Rip;
|
||||
frame.AddrFrame.Offset = ep->ContextRecord->Rbp;
|
||||
|
|
|
@ -2557,7 +2557,7 @@ struct NoCompSaveFilter : SaveFilter {
|
|||
|
||||
/** Filter using Zlib compression. */
|
||||
struct ZlibLoadFilter : LoadFilter {
|
||||
z_stream z; ///< Stream state we are reading from.
|
||||
z_stream z{}; ///< Stream state we are reading from.
|
||||
uint8_t fread_buf[MEMORY_CHUNK_SIZE]; ///< Buffer for reading from the file.
|
||||
|
||||
/**
|
||||
|
@ -2566,7 +2566,6 @@ struct ZlibLoadFilter : LoadFilter {
|
|||
*/
|
||||
ZlibLoadFilter(std::shared_ptr<LoadFilter> chain) : LoadFilter(std::move(chain))
|
||||
{
|
||||
memset(&this->z, 0, sizeof(this->z));
|
||||
if (inflateInit(&this->z) != Z_OK) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, "cannot initialize decompressor");
|
||||
}
|
||||
|
||||
|
@ -2601,7 +2600,7 @@ struct ZlibLoadFilter : LoadFilter {
|
|||
|
||||
/** Filter using Zlib compression. */
|
||||
struct ZlibSaveFilter : SaveFilter {
|
||||
z_stream z; ///< Stream state we are writing to.
|
||||
z_stream z{}; ///< Stream state we are writing to.
|
||||
uint8_t fwrite_buf[MEMORY_CHUNK_SIZE]; ///< Buffer for writing to the file.
|
||||
|
||||
/**
|
||||
|
@ -2611,7 +2610,6 @@ struct ZlibSaveFilter : SaveFilter {
|
|||
*/
|
||||
ZlibSaveFilter(std::shared_ptr<SaveFilter> chain, uint8_t compression_level) : SaveFilter(std::move(chain))
|
||||
{
|
||||
memset(&this->z, 0, sizeof(this->z));
|
||||
if (deflateInit(&this->z, compression_level) != Z_OK) SlError(STR_GAME_SAVELOAD_ERROR_BROKEN_INTERNAL_ERROR, "cannot initialize compressor");
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,6 @@ public:
|
|||
{
|
||||
uint maxlines;
|
||||
uint y;
|
||||
PcxHeader pcx;
|
||||
bool success;
|
||||
|
||||
if (pixelformat == 32) {
|
||||
|
@ -58,9 +57,8 @@ public:
|
|||
if (!of.has_value()) return false;
|
||||
auto &f = *of;
|
||||
|
||||
memset(&pcx, 0, sizeof(pcx));
|
||||
|
||||
/* setup pcx header */
|
||||
PcxHeader pcx{};
|
||||
pcx.manufacturer = 10;
|
||||
pcx.version = 5;
|
||||
pcx.rle = 1;
|
||||
|
|
|
@ -75,8 +75,7 @@ public:
|
|||
|
||||
/* Try to add some game metadata to the PNG screenshot so
|
||||
* it's more useful for debugging and archival purposes. */
|
||||
png_text_struct text[2];
|
||||
memset(text, 0, sizeof(text));
|
||||
png_text_struct text[2]{};
|
||||
text[0].key = const_cast<char *>("Software");
|
||||
text[0].text = const_cast<char *>(_openttd_revision.c_str());
|
||||
text[0].text_length = _openttd_revision.size();
|
||||
|
|
|
@ -680,8 +680,7 @@ static std::vector<char> Gunzip(std::span<char> input)
|
|||
static const int BLOCKSIZE = 8192;
|
||||
std::vector<char> output;
|
||||
|
||||
z_stream z;
|
||||
memset(&z, 0, sizeof(z));
|
||||
z_stream z{};
|
||||
z.next_in = reinterpret_cast<Bytef *>(input.data());
|
||||
z.avail_in = static_cast<uInt>(input.size());
|
||||
|
||||
|
|
|
@ -152,9 +152,7 @@ bool VideoDriver_Win32Base::MakeWindow(bool full_screen, bool resize)
|
|||
}
|
||||
|
||||
if (full_screen) {
|
||||
DEVMODE settings;
|
||||
|
||||
memset(&settings, 0, sizeof(settings));
|
||||
DEVMODE settings{};
|
||||
settings.dmSize = sizeof(settings);
|
||||
settings.dmFields =
|
||||
DM_BITSPERPEL |
|
||||
|
|
Loading…
Reference in New Issue