binaryurp/qa/test-cache.cxx |   20 ++++++++++++--------
 1 file changed, 12 insertions(+), 8 deletions(-)

New commits:
commit fc2413e9a8f509bc6835cae473bf5053728c419a
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Wed Apr 13 17:48:13 2022 +0200
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Thu Apr 14 09:58:00 2022 +0200

    Pick better variable types
    
    ...tweaking the code slightly to guarantee that j will always be 
non-negative
    
    Change-Id: Ie8ba450884cc8b12e0caa79b4d75f95dd96cc120
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132993
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>

diff --git a/binaryurp/qa/test-cache.cxx b/binaryurp/qa/test-cache.cxx
index c024f1f711d6..c4696f78395f 100644
--- a/binaryurp/qa/test-cache.cxx
+++ b/binaryurp/qa/test-cache.cxx
@@ -17,6 +17,10 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
+#include <sal/config.h>
+
+#include <cstddef>
+
 #include <sal/types.h>
 #include <cppunit/TestAssert.h>
 #include <cppunit/TestFixture.h>
@@ -39,13 +43,13 @@ private:
 // cf. jurt/test/com/sun/star/lib/uno/protocols/urp/Cache_Test.java:
 void Test::testNothingLostFromLruList() {
     int a[8];
-    for (int i = 0; i != int(std::size(a)); ++i) {
-        for (int j = 0; j != i; ++j) {
+    for (std::size_t i = 0; i != std::size(a); ++i) {
+        for (std::size_t j = 0; j != i; ++j) {
             a[j] = 0;
         }
         for (;;) {
             binaryurp::Cache< int > c(4);
-            for (int k = 0; k != i; ++k) {
+            for (std::size_t k = 0; k != i; ++k) {
                 bool f;
                 c.add(a[k], &f);
             }
@@ -53,15 +57,15 @@ void Test::testNothingLostFromLruList() {
             CPPUNIT_ASSERT_EQUAL(
                 6,
                 c.add(-1, &f) + c.add(-2, &f) + c.add(-3, &f) + c.add(-4, &f));
-            int j = i - 1;
-            while (j >= 0 && a[j] == 3) {
+            std::size_t j = i;
+            while (j != 0 && a[j - 1] == 3) {
                 --j;
             }
-            if (j < 0) {
+            if (j == 0) {
                 break;
             }
-            ++a[j];
-            for (int k = j + 1; k != i; ++k) {
+            ++a[j - 1];
+            for (std::size_t k = j; k != i; ++k) {
                 a[k] = 0;
             }
         }

Reply via email to