]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3210] miscellaneous warning fixes in lib/util
authorAndrei Pavel <andrei@isc.org>
Mon, 4 Mar 2024 09:46:36 +0000 (11:46 +0200)
committerAndrei Pavel <andrei@isc.org>
Thu, 21 Mar 2024 16:30:04 +0000 (18:30 +0200)
- Wsign-compare
- Wshadow
- doxygen warnings
- fix compilation for src/lib/util/tests/Makefile.am

12 files changed:
src/lib/util/boost_time_utils.cc
src/lib/util/chrono_time_utils.cc
src/lib/util/encode/encode.cc
src/lib/util/encode/encode.h
src/lib/util/str.h
src/lib/util/tests/Makefile.am
src/lib/util/tests/boost_time_utils_unittest.cc
src/lib/util/tests/buffer_unittest.cc
src/lib/util/tests/chrono_time_utils_unittest.cc
src/lib/util/tests/readwrite_mutex_unittest.cc
src/lib/util/tests/run_unittests.cc
src/lib/util/tests/unlock_guard_unittests.cc

index 3719f727f4168c811e990f5f31d051bd2c455bc2..baec64cdd4f82fb683a2f101da8110e8b525322a 100644 (file)
@@ -34,7 +34,7 @@ isc::util::durationToText(boost::posix_time::time_duration dur, size_t fsecs_pre
         size_t fsecs = dur.fractional_seconds();
         size_t width = MAX_FSECS_PRECISION;
         if (fsecs_precision < width) {
-            for (auto i = 0; i < width - fsecs_precision; ++i) {
+            for (size_t i = 0; i < width - fsecs_precision; ++i) {
                 fsecs /= 10;
             }
 
index 6c76112fd441fb0661c47e2a72f103dbdb52add7..109065eab783874ba442d4b20c6f248daeb38c70 100644 (file)
@@ -36,7 +36,7 @@ clockToText(std::chrono::system_clock::time_point t, size_t fsecs_precision) {
         auto fsecs = frac.count();
         size_t width = MAX_FSECS_PRECISION;
         if (fsecs_precision < width) {
-            for (auto i = 0; i < width - fsecs_precision; ++i) {
+            for (size_t i = 0; i < width - fsecs_precision; ++i) {
                 fsecs /= 10;
             }
 
@@ -72,7 +72,7 @@ durationToText(Duration dur, size_t fsecs_precision) {
         auto fsecs = frac.count();
         size_t width = MAX_FSECS_PRECISION;
         if (fsecs_precision < width) {
-            for (auto i = 0; i < width - fsecs_precision; ++i) {
+            for (size_t i = 0; i < width - fsecs_precision; ++i) {
                 fsecs /= 10;
             }
 
index c318849f9fe99e4411ccd5ec34393ad0008d6fe2..01b91ccae217a3100ae9cd8b2dbe72a992ff16d1 100644 (file)
@@ -80,7 +80,7 @@ BaseNEncoder::encode(const std::vector<uint8_t>& input) {
     // the digit and start the index value over.
 
     int digit_idx = 0;          // Digit index we are currently constructing.
-    int cnt = 0;                // How many bits we have in the current digit idx
+    size_t cnt = 0;             // How many bits we have in the current digit idx
     int cur_byte = 0;           // Current input byte.
     uint8_t cur_bit_mask = 0x0; // Bitmask of the current bit in the current byte.
     auto bytes = input.begin(); // Start with the first byte.
@@ -199,7 +199,7 @@ BaseNEncoder::decode(const std::string& encoded_str, std::vector<uint8_t>& outpu
         dig_bits <<= shift_bits;
 
         // Add digit's decoded bits to current byte.
-        for (auto i = 0; i < bits_per_digit_; ++i) {
+        for (size_t i = 0; i < bits_per_digit_; ++i) {
             if (cur_bit_cnt < 8) {
                 // Shift contents over one to make room for next bit.
                 cur_byte <<= 1;
index 379c9da9681559a66a3233ac0d6ead57a30301bc..5365f4239cf8677c3e0e15b8eb4a332c50b4372b 100644 (file)
@@ -47,6 +47,7 @@ public:
     /// @brief Encodes binary data using the encoder's algorithm
     ///
     /// @param input binary data to encode
+    ///
     /// @return resultant encoded data string
     /// @throw BadValue if an error occurs during encoding
     std::string encode(const std::vector<uint8_t>& input);
@@ -55,12 +56,14 @@ public:
     ///
     /// @param encoded_str encoded string to decode
     /// @param[out] output vector into which the decoded data is stored
+    ///
     /// @throw BadValue if an error occurs during decoding
     void decode(const std::string& encoded_str, std::vector<uint8_t>& output);
 
     /// @brief Translate a byte of binary data into the appropriate algorithm digit
     ///
     /// @param bits binary value to translate
+    ///
     /// @return char containing the digit corresponding to the binary value
     /// @throw BadValue if the bits value is out of range
     char bitsToDigit(uint8_t bits);
@@ -72,6 +75,7 @@ public:
     /// char is invalid.
     ///
     /// @param digit the algorithm digit to translate
+    ///
     /// @return byte containing the binary value corresponding to the digit
     uint8_t digitToBits(uint8_t digit);
 
@@ -249,6 +253,7 @@ std::string encodeBase32Hex(const std::vector<uint8_t>& binary);
 ///
 /// @param encoded_str string containing a base32-hex encoded value.
 /// @param[out] output vector into which the decoded binary data is stored.
+///
 /// @throw BadValue if the input string is invalid.
 void decodeBase32Hex(const std::string& encoded_str, std::vector<uint8_t>& output);
 
@@ -262,6 +267,7 @@ std::string encodeBase64(const std::vector<uint8_t>& binary);
 ///
 /// @param encoded_str string containing a base64 encoded value.
 /// @param[out] output vector into which the decoded binary data is stored.
+///
 /// @throw BadValue if the input string is invalid.
 void decodeBase64(const std::string& encoded_str, std::vector<uint8_t>& output);
 
@@ -275,12 +281,14 @@ std::string encodeHex(const std::vector<uint8_t>& binary);
 ///
 /// @param encoded_str string containing a base16 encoded value.
 /// @param[out] output vector into which the decoded binary data is stored.
+///
 /// @throw BadValue if the input string is invalid.
 void decodeHex(const std::string& encoded_str, std::vector<uint8_t>& output);
 
 /// @brief Encode in hexadecimal inline.
 ///
 /// @param value the value to encode.
+///
 /// @return 0x followed by the value encoded in hex.
 inline std::string toHex(std::string value) {
     std::vector<uint8_t> bin(value.begin(), value.end());
index 1e5d4c405f6235abd94080cd536c547b7d83dadd..220b5417df3d87274ab4208c426fff1ef660a962 100644 (file)
@@ -1,30 +1,30 @@
 // Copyright (C) 2011-2024 Internet Systems Consortium, Inc. ("ISC")
-//
+// 
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
 #ifndef KEA_UTIL_STR_H
 #define KEA_UTIL_STR_H
 
 #include <exceptions/exceptions.h>
-
-#include <algorithm>
+#include <algorithm> 
 #include <cstddef>
 #include <cstdint>
 #include <memory>
 #include <sstream>
 #include <string>
-#include <vector>
+#include <vector> 
 
 #include <boost/lexical_cast.hpp>
-
-namespace isc {
-namespace util {
-namespace str {
-
+namespace isc { 
+namespace util { 
+namespace str { 
 /// @brief A Set of C++ Utilities for Manipulating Strings
-
 ///
 /// @brief A standard string util exception that is thrown if getToken or
 /// numToToken are called with bad input data
@@ -36,16 +36,16 @@ public:
 };
 
 /// @brief Trim leading and trailing spaces.
-///
-/// Returns a copy of the input string but with any leading or trailing spaces
-/// or tabs removed.
-///
+/// 
+/// Returns a copy of the input string but with any leading or trailing spaces 
+/// or tabs removed. 
+/// 
 /// @param input Input string to modify.
-///
+/// 
 /// @return String with leading and trailing spaces removed.
 std::string
 trim(const std::string& input);
-
 /// @brief Finds the "trimmed" end of a buffer
 ///
 /// Works backward from the end of the buffer, looking for the first
@@ -68,71 +68,71 @@ seekTrimmed(Iterator const& begin, Iterator end, uint8_t const trim_val) {
     }
     return (end);
 }
-
 /// @brief Split string into tokens.
-///
-/// Splits a string into tokens (the tokens being delimited by one or more of
+/// 
+/// Splits a string into tokens (the tokens being delimited by one or more of 
 /// the delimiter characters) and returns the tokens in a vector.
 /// Adjacent delimiters are considered to be a single delimiter.
-///
-/// Special cases are:
-/// -# The empty string is considered to be zero tokens.
-/// -# A string comprising nothing but delimiters is considered to be zero
-///    tokens.
-///
-/// The reasoning behind this is that the string can be thought of as having
-/// invisible leading and trailing delimiter characters.  Therefore both cases
-/// reduce to a set of contiguous delimiters, which are considered a single
-/// delimiter (so getting rid of the string).
+/// 
+/// Special cases are: 
+/// -# The empty string is considered to be zero tokens. 
+/// -# A string comprising nothing but delimiters is considered to be zero 
+///    tokens. 
+/// 
+/// The reasoning behind this is that the string can be thought of as having 
+/// invisible leading and trailing delimiter characters.  Therefore both cases 
+/// reduce to a set of contiguous delimiters, which are considered a single 
+/// delimiter (so getting rid of the string). 
 /// Optional escape allows to escape delimiter characters (and *only* them
 /// and the escape character itself) using backslash.
-///
-/// We could use Boost for this, but this (simple) function eliminates one
-/// dependency in the code.
-///
+/// 
+/// We could use Boost for this, but this (simple) function eliminates one 
+/// dependency in the code. 
+/// 
 /// @param text String to be split.  Passed by value as the internal copy is
-/// altered during the processing.
+/// altered during the processing. 
 /// @param delim Delimiter characters
 /// @param escape Use backslash to escape delimiter characters
-///
+/// 
 /// @return Vector of tokens.
 std::vector<std::string>
 tokens(const std::string& text, const std::string& delim = " \t\n", bool escape = false);
-
 /// @brief Convert character to uppercase.
-///
+/// 
 /// Used in uppercase() to pass as a parameter to std::transform().  The
 /// function std::toupper() can't be used as it takes an "int" as its parameter;
-/// this confuses the template expansion mechanism because dereferencing a
-/// string::iterator returns a char.
-///
+/// this confuses the template expansion mechanism because dereferencing a 
+/// string::iterator returns a char. 
+/// 
 /// @param chr Character to be upper-cased.
-///
+/// 
 /// @return Uppercase version of the input character.
 char
 toUpper(char const chr);
-
 /// @brief Convert string to uppercase.
-///
+/// 
 /// @param text String to be upper-cased.
 void
 uppercase(std::string& text);
-
 /// @brief Convert character to lowercase.
-///
+/// 
 /// Used in lowercase() to pass as a parameter to std::transform().  The
 /// function std::tolower() can't be used as it takes an "int" as its parameter;
-/// this confuses the template expansion mechanism because dereferencing a
-/// string::iterator returns a char.
-///
+/// this confuses the template expansion mechanism because dereferencing a 
+/// string::iterator returns a char. 
+/// 
 /// @param chr Character to be lower-cased.
-///
+/// 
 /// @return Lowercase version of the input character.
 char
 toLower(char const chr);
-
 /// @brief Convert string to lowercase.
-///
+/// 
 /// @param text String to be lower-cased.
 void
 lowercase(std::string& text);
@@ -288,5 +288,5 @@ dumpAsHex(const uint8_t* data, size_t length);
 }  // namespace str
 }  // namespace util
 }  // namespace isc
-
 #endif  // KEA_UTIL_STR_H
index 6a107a5910960d1db3f4c2422eaccd776f92c010..050a3d38d37e7308f980221abe1642069e875711 100644 (file)
@@ -1,28 +1,29 @@
-SUBDIRS = .
-
-AM_CPPFLAGS = -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
-AM_CPPFLAGS += $(BOOST_INCLUDES)
+SUBDIRS = . 
+AM_CPPFLAGS  =
 AM_CPPFLAGS += -DABS_SRCDIR=\"$(abs_srcdir)\"
 AM_CPPFLAGS += -DTEST_DATA_BUILDDIR=\"$(abs_builddir)\"
+AM_CPPFLAGS += -I$(top_builddir)/src/lib -I$(top_srcdir)/src/lib
+AM_CPPFLAGS += $(BOOST_INCLUDES)
 AM_CXXFLAGS = $(KEA_CXXFLAGS)
-
-if USE_STATIC_LINK
-AM_LDFLAGS = -static
-endif
-
-CLEANFILES = *.gcno *.gcda
+if USE_STATIC_LINK 
+AM_LDFLAGS = -static 
+endif 
+CLEANFILES = *.gcno *.gcda 
 # CSV files are created by unit tests for CSVFile class.
 CLEANFILES += *.csv
-
 TESTS_ENVIRONMENT = $(LIBTOOL) --mode=execute $(VALGRIND_COMMAND)
 
-TESTS =
-if HAVE_GTEST
-TESTS += run_unittests
+TESTS = 
+if HAVE_GTEST 
+TESTS += run_unittests 
 run_unittests_SOURCES  = run_unittests.cc
 run_unittests_SOURCES += bigint_unittest.cc
 run_unittests_SOURCES += boost_time_utils_unittest.cc
-run_unittests_SOURCES += buffer_unittest.cc
+run_unittests_SOURCES += buffer_unittest.cc 
 run_unittests_SOURCES += chrono_time_utils_unittest.cc
 run_unittests_SOURCES += csv_file_unittest.cc
 run_unittests_SOURCES += dhcp_space_unittest.cc
@@ -30,39 +31,38 @@ run_unittests_SOURCES += doubles_unittest.cc
 run_unittests_SOURCES += encode_unittest.cc
 run_unittests_SOURCES += fd_share_tests.cc
 run_unittests_SOURCES += fd_tests.cc
-run_unittests_SOURCES += file_utilities_unittest.cc
-run_unittests_SOURCES += filename_unittest.cc
+run_unittests_SOURCES += filesystem_unittests.cc
 run_unittests_SOURCES += hash_unittest.cc
-run_unittests_SOURCES += io_utilities_unittest.cc
+run_unittests_SOURCES += io_unittests.cc
 run_unittests_SOURCES += labeled_value_unittest.cc
-run_unittests_SOURCES += memory_segment_local_unittest.cc
-run_unittests_SOURCES += memory_segment_common_unittest.h
 run_unittests_SOURCES += memory_segment_common_unittest.cc
+run_unittests_SOURCES += memory_segment_common_unittest.h
+run_unittests_SOURCES += memory_segment_local_unittest.cc
 run_unittests_SOURCES += multi_threading_mgr_unittest.cc
 run_unittests_SOURCES += optional_unittest.cc
 run_unittests_SOURCES += pid_file_unittest.cc
+run_unittests_SOURCES += range_utilities_unittest.cc
+run_unittests_SOURCES += readwrite_mutex_unittest.cc
 run_unittests_SOURCES += staged_value_unittest.cc
 run_unittests_SOURCES += state_model_unittest.cc
-run_unittests_SOURCES += strutil_unittest.cc
+run_unittests_SOURCES += stopwatch_unittest.cc
+run_unittests_SOURCES += str_unittests.cc
 run_unittests_SOURCES += thread_pool_unittest.cc
 run_unittests_SOURCES += triplet_unittest.cc
-run_unittests_SOURCES += range_utilities_unittest.cc
-run_unittests_SOURCES += readwrite_mutex_unittest.cc
-run_unittests_SOURCES += stopwatch_unittest.cc
 run_unittests_SOURCES += unlock_guard_unittests.cc
 run_unittests_SOURCES += utf8_unittest.cc
 run_unittests_SOURCES += versioned_csv_file_unittest.cc
 run_unittests_SOURCES += watch_socket_unittests.cc
 run_unittests_SOURCES += watched_thread_unittest.cc
 
-run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
-run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
-
+run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES) 
+run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS) 
 run_unittests_LDADD  = $(top_builddir)/src/lib/util/unittests/libutil_unittests.la
 run_unittests_LDADD += $(top_builddir)/src/lib/util/io/libkea-util-io.la
 run_unittests_LDADD += $(top_builddir)/src/lib/util/libkea-util.la
 run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libkea-exceptions.la
 run_unittests_LDADD += $(GTEST_LDADD)
-endif
-
-noinst_PROGRAMS = $(TESTS)
+endif 
+noinst_PROGRAMS = $(TESTS) 
index e7e8c81ddf003e4f2c0a113eb3519113a1f0b689..3ec4b98a3a6a0aa091c73e4e9e2fc0073ab7d80f 100644 (file)
@@ -31,7 +31,7 @@ TEST(BoostTimeUtilsTest, epoch) {
     // secs/1000 and so on.  The initial string has no fraction seconds.
     std::string expected("1970-01-01 00:00:00");
     std::string sepoch;
-    for (int precision = 0; precision <= MAX_FSECS_PRECISION; ++precision) {
+    for (size_t precision = 0; precision <= MAX_FSECS_PRECISION; ++precision) {
         if (precision == 1) {
             // Adding fractional seconds so we need append a decimal point.
             expected.push_back('.');
@@ -71,7 +71,7 @@ TEST(BoostTimeUtilsTest, bastilleDay) {
     // secs/1000 and so on.  The initial string has no fraction seconds.
     std::string expected("2015-07-14 12:13:14");
     std::string sbast;
-    for (int precision = 0; precision <= MAX_FSECS_PRECISION; ++precision) {
+    for (size_t precision = 0; precision <= MAX_FSECS_PRECISION; ++precision) {
         if (precision == 1) {
             // Adding fractional seconds so we need append a decimal point
             // and the digit 5 (i.e. 500 ms = .5 secs).
index 1978b4745bf0bff26528b7eaf78d29b7b8cd7a81..1c985713b12e557162a18d6df4df7fbeb1af7f21 100644 (file)
@@ -252,7 +252,7 @@ TEST_F(BufferTest, outputBufferAssign) {
         another = obuffer;
         ASSERT_EQ(sizeof(testdata), another.getLength());
         ASSERT_NE(obuffer.getData(), another.getData());
-        for (int i = 0; i < sizeof(testdata); i ++) {
+        for (size_t i = 0; i < sizeof(testdata); ++i) {
             EXPECT_EQ(testdata[i], another[i]);
             if (i + 1 < sizeof(testdata)) {
                 obuffer.writeUint16At(0, i);
index e9d29172330ebd1646ab68918a6bfc279210a475..22f489cbba8b6df8bd372cc630cb98482c11016d 100644 (file)
@@ -36,7 +36,7 @@ TEST(ChronoTimeUtilsTest, epoch) {
     // secs/1000 and so on.  The initial string has no fraction seconds.
     std::string expected("1970-01-01 00:00:00");
     std::string sepoch;
-    for (int precision = 0; precision <= MAX_FSECS_PRECISION; ++precision) {
+    for (size_t precision = 0; precision <= MAX_FSECS_PRECISION; ++precision) {
         if (precision == 1) {
             // Adding fractional seconds so we need append a decimal point.
             expected.push_back('.');
@@ -75,7 +75,7 @@ TEST(ChronoTimeUtilsTest, duration) {
     // secs/1000 and so on.  The initial string has no fraction seconds.
     std::string expected("01:02:03");
     std::string s123;
-    for (int precision = 0; precision <= MAX_FSECS_PRECISION; ++precision) {
+    for (size_t precision = 0; precision <= MAX_FSECS_PRECISION; ++precision) {
         if (precision == 1) {
             // Adding fractional seconds so we need append a decimal point.
             expected.push_back('.');
@@ -122,7 +122,7 @@ TEST(ChronoTimeUtilsTest, bastilleDay) {
     // secs/1000 and so on.  The initial string has no fraction seconds.
     std::string expected("2015-07-14 12:13:14");
     std::string sbast;
-    for (int precision = 0; precision <= MAX_FSECS_PRECISION; ++precision) {
+    for (size_t precision = 0; precision <= MAX_FSECS_PRECISION; ++precision) {
         if (precision == 1) {
             // Adding fractional seconds so we need append a decimal point
             // and the digit 5 (i.e. 500 ms = .5 secs).
index 6b4af5febcd16feeea5aa6ec160a055671e6f92b..583179df4315a302e114d77a9a521a5a4bcdba7c 100644 (file)
@@ -418,7 +418,7 @@ TEST_F(ReadWriteMutexTest, readWriteRead) {
 
                 // Verify the reader thread is waiting for the read lock.
                 cout << "pausing for one second" << std::endl;
-                bool ret = syncr_.done_cv.wait_for(doner_lock, chrono::seconds(1), [this](){ return syncr_.done; });
+                ret = syncr_.done_cv.wait_for(doner_lock, chrono::seconds(1), [this](){ return syncr_.done; });
 
                 EXPECT_FALSE(syncr_.done);
                 EXPECT_FALSE(ret);
index ef2a372ddc4282fd0fc6fd4f449b5f4b215bbf65..7335822c7b5161abde585c7943fe78cd7d5da334 100644 (file)
@@ -1,18 +1,18 @@
 // Copyright (C) 2011-2015 Internet Systems Consortium, Inc. ("ISC")
-//
+// 
 // This Source Code Form is subject to the terms of the Mozilla Public
 // License, v. 2.0. If a copy of the MPL was not distributed with this
 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
 #include <config.h>
 
-#include <gtest/gtest.h>
 #include <util/unittests/run_all.h>
-#include <stdlib.h>
-
-int
-main(int argc, char* argv[]) {
-    ::testing::InitGoogleTest(&argc, argv);
+#include <gtest/gtest.h>
+int 
+main(int argc, char* argv[]) { 
+    ::testing::InitGoogleTest(&argc, argv); 
 
     return (isc::util::unittests::run_all());
-}
+} 
index 65d868b66e7b8c2defe30856fec3d0684abe8b72..0ff4beef7dd8318ab0bffb25d83d3c27a600696a 100644 (file)
@@ -174,7 +174,7 @@ TEST_F(UnlockGuardTest, testMutex) {
         {
             // call lock_guard constructor which locks mutex resulting in an
             // exception as the mutex is already locked (dead lock)
-            EXPECT_THROW(lock_guard<TestMutex> lock(*test_mutex.get()),
+            EXPECT_THROW(lock_guard<TestMutex> lock2(*test_mutex.get()),
                          isc::InvalidOperation);
             // expect lock 1 lock_count 1 unlock_count 0 dead_lock true
             // you should not be able to get here...using a real mutex
@@ -198,7 +198,7 @@ TEST_F(UnlockGuardTest, testMutex) {
         {
             // call lock_guard constructor which locks mutex but does not block
             // as this is done on the same thread and the mutex is recursive
-            EXPECT_NO_THROW(lock_guard<TestMutex> lock(*test_mutex.get()));
+            EXPECT_NO_THROW(lock_guard<TestMutex> lock2(*test_mutex.get()));
             // expect lock 1 lock_count 2 unlock_count 1 dead_lock false
             // the destructor was already called in EXPECT_NO_THROW scope
             test_mutex->testMutexState(1, 2, 1, false);