From: Amos Jeffries Date: Fri, 30 Sep 2016 19:15:17 +0000 (+1300) Subject: Cleanup: polish Config2 using C++ features X-Git-Tag: SQUID_4_0_15~20 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=871cbc7d9c23ad74194e31d67339fea9dfb09220;p=thirdparty%2Fsquid.git Cleanup: polish Config2 using C++ features We now seem to have had several patches successfully use members declared with default values (C++11 feature) and/or with the "*this = Foo();" shortcut for a reset/clear method. So I think we can start using these to replace old C-style initialization and clear() functions. This patch begins by replacing the Config2 use of memset(). I for one am constantly mistaking which of the Config objects has memset() applied to it at the global level when reconfigure happens. Now we do not need to care, each object handles its own clearing one way or another. --- diff --git a/src/SquidConfig.h b/src/SquidConfig.h index 90eacd6bb1..ae6ac26dcf 100644 --- a/src/SquidConfig.h +++ b/src/SquidConfig.h @@ -547,11 +547,15 @@ extern SquidConfig Config; class SquidConfig2 { public: + void clear() { + *this = SquidConfig2(); + } + struct { - int enable_purge; + int enable_purge = 0; } onoff; - uid_t effectiveUserID; - gid_t effectiveGroupID; + uid_t effectiveUserID = 0; + gid_t effectiveGroupID = 0; }; extern SquidConfig2 Config2; diff --git a/src/cache_cf.cc b/src/cache_cf.cc index 95c4515413..0e191a51b8 100644 --- a/src/cache_cf.cc +++ b/src/cache_cf.cc @@ -613,7 +613,7 @@ parseConfigFile(const char *file_name) static void configDoConfigure(void) { - memset(&Config2, '\0', sizeof(SquidConfig2)); + Config2.clear(); /* init memory as early as possible */ memConfigure(); /* Sanity checks */