Fix presubmit build errors

This change combines the following existing fixes:
- fix ArrowKeyNavigationMenu member initialization order (change 55425)
- use %zu for printing size_t (change 56510)
- fix comparison of different signedness (change 56509)

Change-Id: I4538a7a7fad028c0eaef4cb77f4a877487b61c7a
Signed-off-by: Sui Chen <suichen6@gmail.com>
diff --git a/dbus_capture.cpp b/dbus_capture.cpp
index 715fd41..50ed37f 100644
--- a/dbus_capture.cpp
+++ b/dbus_capture.cpp
@@ -14,8 +14,8 @@
 
 #include "analyzer.hpp"
 #include "histogram.hpp"
-#include "sensorhelper.hpp"
 #include "main.hpp"
+#include "sensorhelper.hpp"
 
 #include <ncurses.h>
 #include <stdlib.h>
@@ -30,11 +30,11 @@
 
 namespace dbus_top_analyzer
 {
-    extern DBusTopStatistics g_dbus_statistics;
-    extern Histogram<float> g_mc_time_histogram;
+extern DBusTopStatistics g_dbus_statistics;
+extern Histogram<float> g_mc_time_histogram;
 } // namespace dbus_top_analyzer
 
-static void TrackMessage(sd_bus_message* m)
+static void TrackMessage([[maybe_unused]] sd_bus_message* m)
 {}
 // Obtain a Monitoring DBus connection
 int AcquireBus(sd_bus** ret)
@@ -188,7 +188,7 @@
             }
             // This is for the bottom-right window
             dbus_top_analyzer::g_dbus_statistics.OnNewDBusMessage(
-            sender_uniq.c_str(), dest_uniq.c_str(), interface, path, member,
+                sender_uniq.c_str(), dest_uniq.c_str(), interface, path, member,
                 type, m);
             sd_bus_message_unref(m);
         }
diff --git a/main.cpp b/main.cpp
index 5293f9b..a61b493 100644
--- a/main.cpp
+++ b/main.cpp
@@ -51,34 +51,34 @@
 
 void ActivateWindowA()
 {
-    g_views[0]->visible_=true;
-    g_views[0]->maximize_=true;
-    g_views[1]->visible_=false;
-    g_views[2]->visible_=false;
+    g_views[0]->visible_ = true;
+    g_views[0]->maximize_ = true;
+    g_views[1]->visible_ = false;
+    g_views[2]->visible_ = false;
 }
 
 void ActivateWindowB()
 {
-    g_views[1]->visible_=true;
-    g_views[1]->maximize_=true;
-    g_views[0]->visible_=false;
-    g_views[2]->visible_=false;
+    g_views[1]->visible_ = true;
+    g_views[1]->maximize_ = true;
+    g_views[0]->visible_ = false;
+    g_views[2]->visible_ = false;
 }
 void ActivateWindowC()
 {
-    g_views[2]->visible_=true;
-    g_views[2]->maximize_=true;
-    g_views[0]->visible_=false;
-    g_views[1]->visible_=false;
+    g_views[2]->visible_ = true;
+    g_views[2]->maximize_ = true;
+    g_views[0]->visible_ = false;
+    g_views[1]->visible_ = false;
 }
 void ActivateAllWindows()
 {
     g_views[0]->maximize_ = false;
-    g_views[1]->maximize_=false;
-    g_views[2]->maximize_=false;
-    g_views[0]->visible_=true;
-    g_views[1]->visible_=true;
-    g_views[2]->visible_= true;
+    g_views[1]->maximize_ = false;
+    g_views[2]->maximize_ = false;
+    g_views[0]->visible_ = true;
+    g_views[1]->visible_ = true;
+    g_views[2]->visible_ = true;
 }
 
 void InitColorPairs()
@@ -89,7 +89,8 @@
 
 // Returns number of lines drawn
 int DrawTextWithWidthLimit(WINDOW* win, std::string txt, int y, int x,
-                           int width, const std::string& delimiters)
+                           int width,
+                           [[maybe_unused]] const std::string& delimiters)
 {
     int ret = 0;
     std::string curr_word, curr_line;
@@ -128,8 +129,9 @@
     for (DBusTopWindow* v : g_views)
     {
         v->OnResize(maxx, maxy);
-        if(v->maximize_){
-            v->rect={0,0,maxx,maxy-MARGIN_BOTTOM};
+        if (v->maximize_)
+        {
+            v->rect = {0, 0, maxx, maxy - MARGIN_BOTTOM};
             v->UpdateWindowSizeAndPosition();
         }
     }
@@ -224,7 +226,7 @@
         {
             switch (c)
             {
-                case '\e': // 27 in dec, 0x1B in hex, escape key
+                case 0x1B: // 27 in dec, 0x1B in hex, escape key
                 {
                     getch();
                     c = getch();
@@ -242,7 +244,7 @@
                         case 'D':
                             curr_view->OnKeyDown("left");
                             break;
-                        case '\e':
+                        case 0x1B:
                             curr_view->OnKeyDown("escape");
                             break;
                     }
@@ -350,7 +352,7 @@
     }
 }
 
-int main(int argc, char** argv)
+int main([[maybe_unused]] int argc, [[maybe_unused]] char** argv)
 {
     int r = AcquireBus(&g_bus);
     if (r <= 0)
diff --git a/menu.cpp b/menu.cpp
index 47d1f57..dcff459 100644
--- a/menu.cpp
+++ b/menu.cpp
@@ -17,8 +17,8 @@
 #include "views.hpp"
 
 ArrowKeyNavigationMenu::ArrowKeyNavigationMenu(DBusTopWindow* view) :
-    win_(view->win), parent_(view), idx0_(INVALID), idx1_(INVALID),
-    h_padding_(2), col_width_(15), h_spacing_(2), choice_(INVALID)
+    win_(view->win), h_padding_(2), col_width_(15), h_spacing_(2),
+    idx0_(INVALID), idx1_(INVALID), choice_(INVALID), parent_(view)
 {}
 
 void ArrowKeyNavigationMenu::do_Render(bool is_column_major)
@@ -71,7 +71,7 @@
                 wattrset(win_, A_REVERSE);
             }
             std::string s = items_[idx];
-            while (s.size() < col_width_)
+            while (s.size() < static_cast<size_t>(col_width_))
             {
                 s.push_back(' ');
             }
@@ -283,11 +283,14 @@
         choice_ = INVALID;
         return;
     }
-    if (c < 0)
-        c = 0;
-    if (c >= static_cast<int>(items_.size()))
+    if (static_cast<size_t>(c) >= items_.size())
     {
-        c = static_cast<int>(items_.size() - 1);
+        c = items_.size() - 1;
+    }
+    if (c < 0)
+    {
+        choice_ = 0;
+        return;
     }
     choice_ = c;
 }
@@ -299,7 +302,7 @@
 
 bool ArrowKeyNavigationMenu::RemoveHighlightedItem(std::string* ret)
 {
-    if (choice_ < 0 || choice_ >= items_.size())
+    if (choice_ < 0 || static_cast<size_t>(choice_) >= items_.size())
         return false;
     std::string r = items_[choice_];
     items_.erase(items_.begin() + choice_);
@@ -309,7 +312,7 @@
     }
     else
     {
-        if (choice_ >= items_.size())
+        if (choice_ > 0 && static_cast<size_t>(choice_) >= items_.size())
         {
             choice_ = items_.size() - 1;
         }
diff --git a/sensorhelper.cpp b/sensorhelper.cpp
index 3f8bba6..ed482e7 100644
--- a/sensorhelper.cpp
+++ b/sensorhelper.cpp
@@ -13,6 +13,7 @@
 // limitations under the License.
 
 #include "sensorhelper.hpp"
+
 #include "main.hpp"
 
 #include <unistd.h>
@@ -62,8 +63,8 @@
 }
 
 // Example: /xyz/openbmc_project/sensors/temperature/powerseq_temp/chassis
-bool IsSensorObjectPathWithAssociation(const std::string& s,
-                                       std::string* sensor_obj_path)
+bool IsSensorObjectPathWithAssociation(
+    const std::string& s, [[maybe_unused]] std::string* sensor_obj_path)
 {
     std::vector<std::string> sections = MySplit(s);
     if (sections.size() == 6)
@@ -100,8 +101,9 @@
 }
 
 std::vector<std::string> FindAllObjectPathsForService(
-    const std::string& service,
-    std::function<void(const std::string&, const std::vector<std::string>&)>
+    [[maybe_unused]] const std::string& service,
+    [[maybe_unused]] std::function<void(const std::string&,
+                                        const std::vector<std::string>&)>
         on_interface_cb)
 {
     // Not available for PCAP replay, only valid with actual DBus capture
diff --git a/views.cpp b/views.cpp
index fdbf85d..5acf160 100644
--- a/views.cpp
+++ b/views.cpp
@@ -454,14 +454,14 @@
         const int col0 = idx0 / nrows + 1, col1 = idx1 / nrows;
         mvwprintw(win, 1, 2, "Columns %d-%d of %d", col0, col1,
                   total_num_columns);
-        mvwprintw(win, 1, rect.w - 15, "%d sensors", sensor_ids_.size());
+        mvwprintw(win, 1, rect.w - 15, "%zu sensors", sensor_ids_.size());
     }
     else if (state == SensorDetail)
     {
         // sensor_ids_ is the cached list of sensors, it should be the same size
         // as the actual number of sensors in the snapshot
         mvwprintw(win, 1, 2, "Details of sensor %s", curr_sensor_id_.c_str());
-        mvwprintw(win, 1, rect.w - 15, "Sensor %d/%u", choice_ + 1,
+        mvwprintw(win, 1, rect.w - 15, "Sensor %d/%zu", choice_ + 1,
                   sensor_ids_.size()); // 1-based
         std::vector<Sensor*> sensors =
             g_sensor_snapshot->FindSensorsBySensorID(curr_sensor_id_);
diff --git a/views.hpp b/views.hpp
index d4f3779..203795d 100644
--- a/views.hpp
+++ b/views.hpp
@@ -21,6 +21,7 @@
 #include "sensorhelper.hpp"
 
 #include <ncurses.h>
+
 #include <string>
 #include <vector>
 constexpr int MARGIN_BOTTOM = 1;
@@ -84,7 +85,7 @@
     SummaryView() : DBusTopWindow()
     {}
     void Render() override;
-    void OnResize(int win_w, int win_h) override
+    void OnResize(int win_w, [[maybe_unused]] int win_h) override
     {
         rect.h = 8;
         rect.w = win_w;
@@ -94,7 +95,7 @@
     }
 
     void UpdateDBusTopStatistics(DBusTopStatistics* stat);
-    void OnKeyDown(const std::string& key) override
+    void OnKeyDown([[maybe_unused]] const std::string& key) override
     {}
     std::string GetStatusString() override
     {
@@ -430,8 +431,8 @@
     };
     SortOrder sort_order_;
 
-    int disp_row_idx_; // From which row to start displaying? (essentially a
-                       // vertical scroll bar)
+    int disp_row_idx_;    // From which row to start displaying? (essentially a
+                          // vertical scroll bar)
     int last_choices_[2]; // Last choice index on either side
     enum MenuState
     {
@@ -451,7 +452,7 @@
         menu2_->win_ = win;
         UpdateWindowSizeAndPosition();
     }
-    
+
   private:
     void SetMenuState(MenuState s)
     {
@@ -519,7 +520,7 @@
         selectable_ = false; // Cannot be selected by the tab key
     }
 
-    void OnKeyDown(const std::string& key) override
+    void OnKeyDown([[maybe_unused]] const std::string& key) override
     {}
     void OnResize(int win_w, int win_h) override
     {
@@ -535,5 +536,4 @@
     {
         return "";
     }
-
 };