From 6c7222e071ffe7d20c138faac0da1d708e0a7779 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sun, 29 Aug 2021 15:12:57 +0100 Subject: Add -Wold-style-cast --- lib/output/pq/pqConn.cpp | 7 ++++--- lib/output/pq/pqRecordSet.cpp | 8 ++++---- lib/output/pq/pqStmt.cpp | 6 +++--- lib/output/pq/writePqCopyStrm.cpp | 2 +- 4 files changed, 12 insertions(+), 11 deletions(-) (limited to 'lib/output') diff --git a/lib/output/pq/pqConn.cpp b/lib/output/pq/pqConn.cpp index 983271e..6d89fb7 100644 --- a/lib/output/pq/pqConn.cpp +++ b/lib/output/pq/pqConn.cpp @@ -34,7 +34,8 @@ namespace MyGrate::Output::Pq { PqConn::query(const char * const q, const std::initializer_list & vs) { Bindings b {vs}; - ResPtr res {PQexecParams(conn.get(), q, (int)vs.size(), nullptr, b.values.data(), b.lengths.data(), nullptr, 0), + ResPtr res {PQexecParams(conn.get(), q, static_cast(vs.size()), nullptr, b.values.data(), b.lengths.data(), + nullptr, 0), &PQclear}; verify(PQresultStatus(res.get()) == PGRES_COMMAND_OK, q, res.get()); } @@ -72,8 +73,8 @@ namespace MyGrate::Output::Pq { {nullptr, [](void * cookie, const char * buf, size_t size) { auto conn = static_cast(cookie)->conn.get(); - verify(PQputCopyData(conn, buf, (int)size) == 1, "copy data", conn); - return (ssize_t)size; + verify(PQputCopyData(conn, buf, static_cast(size)) == 1, "copy data", conn); + return static_cast(size); }, nullptr, [](void * cookie) { diff --git a/lib/output/pq/pqRecordSet.cpp b/lib/output/pq/pqRecordSet.cpp index 4d5349f..9eeb3cd 100644 --- a/lib/output/pq/pqRecordSet.cpp +++ b/lib/output/pq/pqRecordSet.cpp @@ -30,12 +30,12 @@ namespace MyGrate::Output::Pq { DbValue PqRecordSet::at(std::size_t row, std::size_t col) const { - if (PQgetisnull(res.get(), (int)row, (int)col)) { + if (PQgetisnull(res.get(), static_cast(row), static_cast(col))) { return nullptr; } - const auto value {PQgetvalue(res.get(), (int)row, (int)col)}; - const auto size {static_cast(PQgetlength(res.get(), (int)row, (int)col))}; - const auto type {PQftype(res.get(), (int)col)}; + const auto value {PQgetvalue(res.get(), static_cast(row), static_cast(col))}; + const auto size {static_cast(PQgetlength(res.get(), static_cast(row), static_cast(col)))}; + const auto type {PQftype(res.get(), static_cast(col))}; switch (type) { // case BITOID: TODO bool // case BOOLOID: TODO bool diff --git a/lib/output/pq/pqStmt.cpp b/lib/output/pq/pqStmt.cpp index c6399e4..bb7a79c 100644 --- a/lib/output/pq/pqStmt.cpp +++ b/lib/output/pq/pqStmt.cpp @@ -22,8 +22,8 @@ namespace MyGrate::Output::Pq { PqPrepStmt::execute(const std::span vs) { Bindings b {vs}; - res = {PQexecPrepared( - conn, name.c_str(), (int)vs.size(), b.values.data(), b.lengths.data(), b.formats.data(), 0), + res = {PQexecPrepared(conn, name.c_str(), static_cast(vs.size()), b.values.data(), b.lengths.data(), + b.formats.data(), 0), &PQclear}; verify(PQresultStatus(res.get()) == PGRES_COMMAND_OK || PQresultStatus(res.get()) == PGRES_TUPLES_OK, name, conn); @@ -54,7 +54,7 @@ namespace MyGrate::Output::Pq { return i->second; } auto nam {scprintf<"pst%0lx">(c->stmts.size())}; - ResPtr res {PQprepare(c->conn.get(), nam.c_str(), q, (int)n, nullptr), PQclear}; + ResPtr res {PQprepare(c->conn.get(), nam.c_str(), q, static_cast(n), nullptr), PQclear}; verify(PQresultStatus(res.get()) == PGRES_COMMAND_OK, q, c->conn.get()); return c->stmts.emplace(q, std::move(nam)).first->second; } diff --git a/lib/output/pq/writePqCopyStrm.cpp b/lib/output/pq/writePqCopyStrm.cpp index 984b4fd..9d52a46 100644 --- a/lib/output/pq/writePqCopyStrm.cpp +++ b/lib/output/pq/writePqCopyStrm.cpp @@ -84,7 +84,7 @@ namespace MyGrate::Output::Pq { }()}; fputs("\\\\x", out); std::for_each(v.begin(), v.end(), [this](auto b) { - fwrite(hex[(uint8_t)b].data(), 2, 1, out); + fwrite(hex[static_cast(b)].data(), 2, 1, out); }); } } -- cgit v1.2.3