summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2021-09-09 18:58:38 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2021-09-09 18:58:38 +0100
commit779268ce0990e7ff3c1735392899eced4c89f448 (patch)
tree1c93ca65947ebf9f6bfd64f92b1528b62ed7f4d1
parentAdd -Wold-style-cast and fix up mess, mostly glib stuff (diff)
downloadlibadhocutil-779268ce0990e7ff3c1735392899eced4c89f448.tar.bz2
libadhocutil-779268ce0990e7ff3c1735392899eced4c89f448.tar.xz
libadhocutil-779268ce0990e7ff3c1735392899eced4c89f448.zip
Fix conversions in everything but uriParse
-rw-r--r--libadhocutil/compileTimeFormatter.h2
-rw-r--r--libadhocutil/ctf-impl/printf-compat.h8
-rw-r--r--libadhocutil/curlHandle.cpp2
-rw-r--r--libadhocutil/fileUtils.cpp5
-rw-r--r--libadhocutil/fileUtils.h3
-rw-r--r--libadhocutil/unittests/testCompileTimeFormatter.cpp38
-rw-r--r--libadhocutil/unittests/testFileUtils.cpp2
7 files changed, 34 insertions, 26 deletions
diff --git a/libadhocutil/compileTimeFormatter.h b/libadhocutil/compileTimeFormatter.h
index fbbd7bc..de7376b 100644
--- a/libadhocutil/compileTimeFormatter.h
+++ b/libadhocutil/compileTimeFormatter.h
@@ -140,7 +140,7 @@ namespace AdHoc {
template<typename stream, typename char_type>
static inline void
- appendStream(stream & s, const char_type * p, size_t n)
+ appendStream(stream & s, const char_type * p, std::streamsize n)
{
s.write(p, n);
}
diff --git a/libadhocutil/ctf-impl/printf-compat.h b/libadhocutil/ctf-impl/printf-compat.h
index f05ba30..872f9af 100644
--- a/libadhocutil/ctf-impl/printf-compat.h
+++ b/libadhocutil/ctf-impl/printf-compat.h
@@ -98,7 +98,7 @@ namespace AdHoc {
StreamWriterT('n') {
template<typename... Pn>
static inline void
- write(stream & s, int * n, const Pn &... pn)
+ write(stream & s, std::streamoff * n, const Pn &... pn)
{
BOOST_ASSERT_MSG(n, "%n conversion requires non-null parameter");
*n = streamLength(s);
@@ -180,6 +180,12 @@ namespace AdHoc {
static inline void
write(stream & s, int l, const std::string_view & p, const Pn &... pn)
{
+ return write(s, static_cast<size_t>(l), p, pn...);
+ }
+ template<typename... Pn>
+ static inline void
+ write(stream & s, size_t l, const std::string_view & p, const Pn &... pn)
+ {
s << p.substr(0, l);
s.copyfmt(std::ios(nullptr));
StreamWriter::next(s, pn...);
diff --git a/libadhocutil/curlHandle.cpp b/libadhocutil/curlHandle.cpp
index 1df5f12..bcb5fa0 100644
--- a/libadhocutil/curlHandle.cpp
+++ b/libadhocutil/curlHandle.cpp
@@ -93,7 +93,7 @@ namespace AdHoc::Net {
if (res != CURLE_OK) {
long http_code = 0;
if (curl_easy_getinfo(curl_handle, CURLINFO_RESPONSE_CODE, &http_code) == CURLE_OK) {
- throw AdHoc::Net::CurlException(res, curl_easy_strerror(res), http_code);
+ throw AdHoc::Net::CurlException(res, curl_easy_strerror(res), static_cast<short>(http_code));
}
throw AdHoc::Net::CurlException(res, curl_easy_strerror(res), IceUtil::None);
}
diff --git a/libadhocutil/fileUtils.cpp b/libadhocutil/fileUtils.cpp
index 785fb38..4ebcbf2 100644
--- a/libadhocutil/fileUtils.cpp
+++ b/libadhocutil/fileUtils.cpp
@@ -120,13 +120,14 @@ namespace AdHoc::FileUtils {
MemMap::~MemMap()
{
- munmap(const_cast<void *>(data), st.st_size);
+ munmap(const_cast<void *>(data), static_cast<size_t>(st.st_size));
}
void *
MemMap::setupMapInt(int flags) const
{
- return mmap(nullptr, st.st_size, (flags & (O_WRONLY | O_RDWR)) ? PROT_WRITE : PROT_READ, MAP_SHARED, fh, 0);
+ return mmap(nullptr, static_cast<size_t>(st.st_size), (flags & (O_WRONLY | O_RDWR)) ? PROT_WRITE : PROT_READ,
+ MAP_SHARED, fh, 0);
}
void *
diff --git a/libadhocutil/fileUtils.h b/libadhocutil/fileUtils.h
index 59bc41e..f0a3cb2 100644
--- a/libadhocutil/fileUtils.h
+++ b/libadhocutil/fileUtils.h
@@ -169,7 +169,8 @@ namespace AdHoc {
[[nodiscard]] auto
sv() const
{
- return std::basic_string_view<T>(static_cast<const T *>(data), st.st_size / sizeof(T));
+ return std::basic_string_view<T>(
+ static_cast<const T *>(data), static_cast<std::string_view::size_type>(st.st_size) / sizeof(T));
}
#endif
diff --git a/libadhocutil/unittests/testCompileTimeFormatter.cpp b/libadhocutil/unittests/testCompileTimeFormatter.cpp
index ce782fc..a6968c4 100644
--- a/libadhocutil/unittests/testCompileTimeFormatter.cpp
+++ b/libadhocutil/unittests/testCompileTimeFormatter.cpp
@@ -82,7 +82,7 @@ namespace AdHoc {
StreamWriterT('r', 'a') {
template<typename P, typename... Pn>
static void
- write(stream & s, int width, const P & p, const Pn &... pn)
+ write(stream & s, size_t width, const P & p, const Pn &... pn)
{
std::stringstream buf;
buf << p;
@@ -273,7 +273,7 @@ BOOST_AUTO_TEST_SUITE_END();
BOOST_AUTO_TEST_CASE(customMultiArgRightAlign)
{
std::stringstream buf1, buf2, buf3;
- const int width = 20;
+ const auto width = 20U;
Formatter<formatStringMultiArg>::write(buf1, width, "something");
Formatter<formatStringMultiArg>::write(buf2, width, "something else");
Formatter<formatStringMultiArg>::write(buf3, width, 123.45);
@@ -284,7 +284,7 @@ BOOST_AUTO_TEST_CASE(customMultiArgRightAlign)
BOOST_AUTO_TEST_CASE(get)
{
- auto s = Formatter<formatStringMultiArg>::get(20, "something else");
+ auto s = Formatter<formatStringMultiArg>::get(20U, "something else");
BOOST_CHECK_EQUAL(s, "value something else");
}
@@ -303,9 +303,9 @@ constexpr
namespace AdHoc {
template<>
inline void
- appendStream(FILE & strm, const char * const p, size_t n)
+ appendStream(FILE & strm, const char * const p, std::streamsize n)
{
- BOOST_VERIFY(fwrite(p, n, 1, &strm) == 1);
+ BOOST_VERIFY(fwrite(p, static_cast<size_t>(n), 1, &strm) == 1);
}
}
@@ -390,18 +390,18 @@ GLIBC_FMT_TEST(d6, "in %lld.", -123456LL);
GLIBC_FMT_TEST(i1, "in %i.", 123);
GLIBC_FMT_TEST(i2, "in %i.", -123);
-GLIBC_FMT_TEST(x1, "in %x.", 123);
-GLIBC_FMT_TEST(x2, "in %x %d.", 123, 256);
-GLIBC_FMT_TEST(x3, "in %d %x.", 123, 1024);
-GLIBC_FMT_TEST(x4, "in %X %x.", 123, 13);
-GLIBC_FMT_TEST(x5, "in %X %s.", 123, "miXED case after UPPER X");
-GLIBC_FMT_TEST(x6, "in %#x.", 123);
-GLIBC_FMT_TEST(x7, "in %#X.", 123);
-GLIBC_FMT_TEST(x8, "in %#X %x.", 123, 150);
+GLIBC_FMT_TEST(x1, "in %x.", 123U);
+GLIBC_FMT_TEST(x2, "in %x %d.", 123U, 256);
+GLIBC_FMT_TEST(x3, "in %d %x.", 123, 1024U);
+GLIBC_FMT_TEST(x4, "in %X %x.", 123U, 13U);
+GLIBC_FMT_TEST(x5, "in %X %s.", 123U, "miXED case after UPPER X");
+GLIBC_FMT_TEST(x6, "in %#x.", 123U);
+GLIBC_FMT_TEST(x7, "in %#X.", 123U);
+GLIBC_FMT_TEST(x8, "in %#X %x.", 123U, 150U);
-GLIBC_FMT_TEST(o1, "in %o.", 123);
-GLIBC_FMT_TEST(o2, "in %o %d.", 123, 256);
-GLIBC_FMT_TEST(o3, "in %d %o.", 123, 1024);
+GLIBC_FMT_TEST(o1, "in %o.", 123U);
+GLIBC_FMT_TEST(o2, "in %o %d.", 123U, 256);
+GLIBC_FMT_TEST(o3, "in %d %o.", 123, 1024U);
GLIBC_FMT_TEST(a1, "in %a.", 123.456789);
GLIBC_FMT_TEST(a2, "in %a.", -123.456789);
@@ -439,13 +439,13 @@ GLIBC_FMT_TEST(g6, "in %G.", -123.456789);
GLIBC_FMT_TEST(g7, "in %g.", 123456789.123);
GLIBC_FMT_TEST(g8, "in %g.", -123456789.123);
-GLIBC_FMT_TEST(fmtlibt_fmt, "%0.10f:%04d:%+g:%s:%p:%c:%%\n", 1.234, 42, 3.13, "str", reinterpret_cast<void *>(1000),
- static_cast<int>('X'));
+GLIBC_FMT_TEST(
+ fmtlibt_fmt, "%0.10f:%04d:%+g:%s:%p:%c:%%\n", 1.234, 42, 3.13, "str", reinterpret_cast<void *>(1000), 'X');
AdHocFormatter(chars_written_fmt, "%n %s %n %d %n");
BOOST_AUTO_TEST_CASE(chars_written)
{
- int a = -1, b = -1, c = -1;
+ std::streamoff a = -1, b = -1, c = -1;
auto s = chars_written_fmt::get(&a, "some string", &b, 10, &c);
BOOST_CHECK_EQUAL(s, " some string 10 ");
BOOST_CHECK_EQUAL(a, 0);
diff --git a/libadhocutil/unittests/testFileUtils.cpp b/libadhocutil/unittests/testFileUtils.cpp
index e672951..94e4850 100644
--- a/libadhocutil/unittests/testFileUtils.cpp
+++ b/libadhocutil/unittests/testFileUtils.cpp
@@ -117,7 +117,7 @@ BOOST_AUTO_TEST_CASE(memmap)
auto i = f.sv<int>();
BOOST_REQUIRE_EQUAL(i[0], *reinterpret_cast<const int *>("#def"));
BOOST_REQUIRE_EQUAL(i[1], *reinterpret_cast<const int *>("ine "));
- BOOST_REQUIRE_EQUAL(i.length(), f.getStat().st_size / sizeof(int));
+ BOOST_REQUIRE_EQUAL(i.length(), static_cast<size_t>(f.getStat().st_size) / sizeof(int));
}
BOOST_AUTO_TEST_CASE(openmode)