Implement minor suggestions from cppcheck report.
authorDavin McCall <davmac@davmac.org>
Sun, 5 May 2019 04:22:40 +0000 (14:22 +1000)
committerDavin McCall <davmac@davmac.org>
Sun, 5 May 2019 04:22:40 +0000 (14:22 +1000)
src/control.cc
src/dinit.cc
src/includes/service.h

index 744ead35bbc66e92701351583f4f6a36e5b3ce08..8cd6f724e760e77580fed8b1f11b9e373e78344e 100644 (file)
@@ -117,8 +117,7 @@ bool control_conn_t::process_find_load(int pktType)
     
     uint16_t svcSize;
     rbuf.extract((char *)&svcSize, 1, 2);
-    chklen = svcSize + 3; // packet type + (2 byte) length + service name
-    if (svcSize <= 0 || chklen > 1024) {
+    if (svcSize <= 0 || svcSize > (1024 - 3)) {
         // Queue error response / mark connection bad
         char badreqRep[] = { DINIT_RP_BADREQ };
         if (! queue_packet(badreqRep, 1)) return false;
@@ -126,6 +125,7 @@ bool control_conn_t::process_find_load(int pktType)
         iob.set_watches(OUT_EVENTS);
         return true;
     }
+    chklen = svcSize + 3; // packet type + (2 byte) length + service name
     
     if (rbuf.get_length() < chklen) {
         // packet not complete yet; read more
@@ -648,7 +648,7 @@ control_conn_t::handle_t control_conn_t::allocate_service_handle(service_record
     // we find a gap in the handle values.
     handle_t candidate = 0;
     for (auto p : key_service_map) {
-        if (p.first == candidate) candidate++;
+        if (p.first == candidate) ++candidate;
         else break;
     }
 
index 6771bde71d5ac47c8eb392a3b3fc234686a41b96..11795edebf26b237346d3d8101a6c8216ee7c5d7 100644 (file)
@@ -507,11 +507,11 @@ int dinit_main(int argc, char **argv)
     }
     else if (shutdown_type == shutdown_type_t::REBOOT) {
         // Non-system-process. If we got SIGINT, let's die due to it:
-        sigset_t sigwait_set;
-        sigemptyset(&sigwait_set);
-        sigaddset(&sigwait_set, SIGINT);
+        sigset_t sigwait_set_int;
+        sigemptyset(&sigwait_set_int);
+        sigaddset(&sigwait_set_int, SIGINT);
         raise(SIGINT);
-        sigprocmask(SIG_UNBLOCK, &sigwait_set, NULL);
+        sigprocmask(SIG_UNBLOCK, &sigwait_set_int, NULL);
     }
     
     return 0;
index 131c4f8a48666da19157aa7d44d765546e8d39bf..89592068bd13e475ffe8d73f6f786f0959fc3c1b 100644 (file)
@@ -410,7 +410,7 @@ class service_record
 
     public:
 
-    service_record(service_set *set, string name)
+    service_record(service_set *set, const string &name)
         : service_name(name), service_state(service_state_t::STOPPED),
             desired_state(service_state_t::STOPPED), auto_restart(false), smooth_recovery(false),
             pinned_stopped(false), pinned_started(false), waiting_for_deps(false),
@@ -424,7 +424,7 @@ class service_record
         socket_perms = 0;
     }
 
-    service_record(service_set *set, string name, service_type_t record_type_p,
+    service_record(service_set *set, const string &name, service_type_t record_type_p,
             const std::list<prelim_dep> &deplist_p)
         : service_record(set, name)
     {
@@ -481,7 +481,7 @@ class service_record
     }
 
     // Set logfile, should be done before service is started
-    void set_log_file(string logfile)
+    void set_log_file(const string &logfile)
     {
         this->logfile = logfile;
     }