query_param: Set default value of $top to maxEntriesPerPage

Current code initializes $top to std::numeric_limits<size_t>::max(),
when adding with a non-zero $skip value, it overflows. This patch
solves this issue by initializing it to maxEntriesPerPage.

Fixes c937d2b ("Make log services use parameter delegation").

Tested:
Verified providing only $skip in the query parameter in /redfish/v1
/Systems/system/LogServices/EventLog/Entries is properly handled.

Change-Id: Id5668cecda97a78f803941d6eb2e1aa0ba9495aa
Signed-off-by: Jiaqing Zhao <jiaqing.zhao@intel.com>
diff --git a/redfish-core/include/utils/query_param.hpp b/redfish-core/include/utils/query_param.hpp
index 889a684..0e86ec5 100644
--- a/redfish-core/include/utils/query_param.hpp
+++ b/redfish-core/include/utils/query_param.hpp
@@ -16,6 +16,7 @@
 {
 namespace query_param
 {
+inline constexpr size_t maxEntriesPerPage = 1000;
 
 enum class ExpandType : uint8_t
 {
@@ -38,7 +39,7 @@
     size_t skip = 0;
 
     // Top
-    size_t top = std::numeric_limits<size_t>::max();
+    size_t top = maxEntriesPerPage;
 };
 
 // The struct defines how resource handlers in redfish-core/lib/ can handle
@@ -87,7 +88,7 @@
     if (queryCapabilities.canDelegateTop)
     {
         delegated.top = query.top;
-        query.top = std::numeric_limits<size_t>::max();
+        query.top = maxEntriesPerPage;
     }
 
     // delegate skip
@@ -174,7 +175,6 @@
     return getNumericParam(value, query.skip);
 }
 
-static constexpr size_t maxEntriesPerPage = 1000;
 inline QueryError getTopParam(std::string_view value, Query& query)
 {
     QueryError ret = getNumericParam(value, query.top);
@@ -607,7 +607,7 @@
         return;
     }
 
-    if (query.top != std::numeric_limits<size_t>::max() || query.skip != 0)
+    if (query.top <= maxEntriesPerPage || query.skip != 0)
     {
         processTopAndSkip(query, intermediateResponse);
     }
diff --git a/redfish-core/include/utils/query_param_test.cpp b/redfish-core/include/utils/query_param_test.cpp
index 7520f3e..077447f 100644
--- a/redfish-core/include/utils/query_param_test.cpp
+++ b/redfish-core/include/utils/query_param_test.cpp
@@ -75,7 +75,7 @@
         .top = 42,
     };
     Query delegated = delegate(QueryCapabilities{}, query);
-    EXPECT_EQ(delegated.top, std::numeric_limits<size_t>::max());
+    EXPECT_EQ(delegated.top, maxEntriesPerPage);
     EXPECT_EQ(query.top, 42);
 }
 
@@ -89,7 +89,7 @@
     };
     Query delegated = delegate(capabilities, query);
     EXPECT_EQ(delegated.top, 42);
-    EXPECT_EQ(query.top, std::numeric_limits<size_t>::max());
+    EXPECT_EQ(query.top, maxEntriesPerPage);
 }
 
 TEST(Delegate, SkipNegative)