diff --git a/CMakeLists.txt b/CMakeLists.txt index 019a78c..8a7f659 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,10 @@ set( CMAKE_CXX_STANDARD 11 ) set( CMAKE_CXX_STANDARD_REQUIRED ON ) set( CMAKE_CXX_EXTENSIONS OFF ) +if (CMAKE_CXX_COMPILER_ID MATCHES "GNU") + set( CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Werror -Wall -Wconversion -Wno-sign-conversion -Wextra" ) +endif() + # Libraries find_package(OpenSSL 1.1 REQUIRED) diff --git a/src/base58.cpp b/src/base58.cpp index 38304c7..cd3eccd 100644 --- a/src/base58.cpp +++ b/src/base58.cpp @@ -24,6 +24,7 @@ * * Based on code from https://github.com/bitcoin/bitcoin/blob/f1e2f2a85962c1664e4e55471061af0eaa798d40/src/base58.cpp */ +#include #include #include "base58.h" @@ -39,7 +40,7 @@ std::string base58_encode(const unsigned char* pbegin, const unsigned char* pend zeroes++; } // Allocate enough space in big-endian base58 representation. - int size = (pend - pbegin) * 138 / 100 + 1; // log(256) / log(58), rounded up. + std::size_t size = (pend - pbegin) * 138 / 100 + 1; // log(256) / log(58), rounded up. std::vector b58(size); // Process the bytes. while (pbegin != pend) { @@ -48,7 +49,7 @@ std::string base58_encode(const unsigned char* pbegin, const unsigned char* pend // Apply "b58 = b58 * 256 + ch". for (std::vector::reverse_iterator it = b58.rbegin(); (carry != 0 || i < length) && (it != b58.rend()); it++, i++) { carry += 256 * (*it); - *it = carry % 58; + *it = static_cast(carry % 58); carry /= 58; } diff --git a/src/checksum.cpp b/src/checksum.cpp index 3c29dcb..53c7e33 100644 --- a/src/checksum.cpp +++ b/src/checksum.cpp @@ -26,13 +26,13 @@ #include #include "checksum.h" -inline void sha256d(const unsigned char *data, unsigned int len, unsigned char *out) { +inline void sha256d(const unsigned char *data, std::size_t len, unsigned char *out) { SHA256(data, len, out); SHA256(out, 32, out); } #define checksum_impl(name, func) \ - checksum_t checksum_##name(const unsigned char *data, unsigned int len) { \ + checksum_t checksum_##name(const unsigned char *data, std::size_t len) { \ \ checksum_t crc; \ unsigned char hash[32]; \ diff --git a/src/checksum.h b/src/checksum.h index 44bfef8..57f50e8 100644 --- a/src/checksum.h +++ b/src/checksum.h @@ -24,12 +24,13 @@ #ifndef CHECKSUM_H #define CHECKSUM_H +#include #include typedef std::array checksum_t; -checksum_t checksum_sha256d(const unsigned char *data, unsigned int len); +checksum_t checksum_sha256d(const unsigned char *data, std::size_t len); -checksum_t checksum_ripemd160(const unsigned char *data, unsigned int len); +checksum_t checksum_ripemd160(const unsigned char *data, std::size_t len); #endif /* CHECKSUM_H */ diff --git a/src/key_search_mt.cpp b/src/key_search_mt.cpp index 881ed53..e3d22cc 100644 --- a/src/key_search_mt.cpp +++ b/src/key_search_mt.cpp @@ -1,4 +1,5 @@ +#include #include #include #include @@ -7,10 +8,10 @@ #include "key_search.h" // Max keys to search for, -unsigned int g_max; +std::size_t g_max; // How many keys we have found so far. -unsigned int g_count; +std::size_t g_count; // Mutex guard for g_count. std::mutex g_count_mtx; @@ -60,7 +61,7 @@ void KeySearch::_search_mt(size_t n) g_count = 0; // Launch them. - for(int i = 0; i < t.size(); i++) { + for(std::size_t i = 0; i < t.size(); i++) { t[i] = std::thread(_thr_proc, m_words); } @@ -68,7 +69,7 @@ void KeySearch::_search_mt(size_t n) _thr_proc(m_words); // Wait for all threads to compelete. - for(int i = 0; i < t.size(); i++) { + for(std::size_t i = 0; i < t.size(); i++) { t[i].join(); } } diff --git a/src/main.cpp b/src/main.cpp index a68eed7..fa4d050 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,7 +46,7 @@ void cmd_search(int argc, char **argv) { if (option_l33t) { strlist_t tmp = strsplitwords(input); - for(int i = 0; i < tmp.size(); i++) { + for(std::size_t i = 0; i < tmp.size(); i++) { ks.addList(l33twords(tmp[i])); } } else { diff --git a/src/string.cpp b/src/string.cpp index 8793fa1..bee3330 100644 --- a/src/string.cpp +++ b/src/string.cpp @@ -21,8 +21,9 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. */ -#include +#include #include +#include #include "string.h" strlist_t strsplitwords(const std::string& str, const std::string& delim) { @@ -108,20 +109,20 @@ static bool is_l33t(char ch, char& r) { // '1', '2', '3', '4', '5', '6', '7', '8', '9' static char alphabet[9] = { 'l', 'z', 'e', 'a', 's', 'G', 't', 'B', 'g' }; - for(int i = 0; i < sizeof(alphabet) / sizeof(char); i++) { + for(std::size_t i = 0; i < sizeof(alphabet) / sizeof(char); i++) { if (ch == alphabet[i]) { - r = '1' + i; + r = static_cast('1' + i); return true; } } return false; } -static void _l33t(strlist_t& list, const std::string& a, int pos) { +static void _l33t(strlist_t& list, const std::string& a, std::size_t pos) { // Find the next character to be replaced. - for(int i = pos; i < a.length(); i++) { + for(std::size_t i = pos; i < a.length(); i++) { char ch; if (is_l33t(a[i], ch)) {