]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Cleanup: polish Config2 using C++ features
authorAmos Jeffries <squid3@treenet.co.nz>
Fri, 30 Sep 2016 19:15:17 +0000 (08:15 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 30 Sep 2016 19:15:17 +0000 (08:15 +1300)
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.

src/SquidConfig.h
src/cache_cf.cc

index 90eacd6bb1b77d1ace9f3b25e5c454f9e18bcc02..ae6ac26dcff3bc34eb4b9e818eab9f0591297c0a 100644 (file)
@@ -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;
index 95c45154138ee4ccc7f2bb1c9b795707442eb1dd..0e191a51b8b71eb3dd11b9bed444e35d7690ad9b 100644 (file)
@@ -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 */