diff options
author | Jack Lloyd <[email protected]> | 2016-04-09 11:23:51 -0400 |
---|---|---|
committer | Jack Lloyd <[email protected]> | 2016-04-09 11:23:51 -0400 |
commit | 8dd6eb9252ad91f59630e2889fa6803f6e3bf554 (patch) | |
tree | 11de0bdbf598afc2a7207e9bbef911716ba54ce1 | |
parent | 5e75f6db1c3d73fdb778d49751f1b2ef4549b177 (diff) |
Fix a couple MSVC warnings.
Cast std::streamsize to size_t since MSVC is worried gcount() might
return a negative number.
The entropy callbacks took the entropy estimate as a size_t instead of
a double, which causes some verbose warnings due to the conversion.
-rw-r--r-- | src/cli/cli.h | 2 | ||||
-rw-r--r-- | src/cli/speed.cpp | 14 | ||||
-rw-r--r-- | src/tests/test_entropy.cpp | 6 |
3 files changed, 12 insertions, 10 deletions
diff --git a/src/cli/cli.h b/src/cli/cli.h index c2609bc55..11cc8add7 100644 --- a/src/cli/cli.h +++ b/src/cli/cli.h @@ -443,7 +443,7 @@ class Command while(in.good()) { in.read(reinterpret_cast<char*>(buf.data()), buf.size()); - consumer_fn(buf.data(), in.gcount()); + consumer_fn(buf.data(), static_cast<size_t>(in.gcount())); } } diff --git a/src/cli/speed.cpp b/src/cli/speed.cpp index ffe10844e..c767b2a55 100644 --- a/src/cli/speed.cpp +++ b/src/cli/speed.cpp @@ -597,13 +597,14 @@ class Speed final : public Command for(auto src : srcs.enabled_sources()) { - size_t entropy_bits = 0, samples = 0; + double entropy_bits = 0.0; + size_t samples = 0; std::vector<size_t> entropy; Botan::Entropy_Accumulator accum( - [&](const uint8_t buf[], size_t buf_len, size_t buf_entropy) -> bool { - entropy.insert(entropy.end(), buf, buf + buf_len); - entropy_bits += buf_entropy; + [&](const uint8_t buf[], size_t buf_len, double buf_entropy) -> bool { + entropy.insert(entropy.end(), buf, buf + buf_len); + entropy_bits += buf_entropy; samples += 1; return (samples > 1024 || entropy_bits > 1024 || clock::now() > deadline); }); @@ -623,8 +624,9 @@ class Speed final : public Command } #endif - output() << "Entropy source " << src << " output " << entropy.size() - << " bytes in " << timer.milliseconds() << " ms"; + output() << "Entropy source " << src << " output " << entropy.size() << " bytes" + << " estimated entropy " << entropy_bits + << " in " << timer.milliseconds() << " ms"; #if defined(BOTAN_HAS_COMPRESSION) if(compressed.size() > 0) diff --git a/src/tests/test_entropy.cpp b/src/tests/test_entropy.cpp index 201dd02b5..406dc7c41 100644 --- a/src/tests/test_entropy.cpp +++ b/src/tests/test_entropy.cpp @@ -40,10 +40,10 @@ class Entropy_Source_Tests : public Test { std::vector<uint8_t> entropy; size_t samples = 0; - size_t entropy_estimate = 0; + double entropy_estimate = 0.0; Botan::Entropy_Accumulator accum( - [&](const uint8_t buf[], size_t buf_len, size_t buf_entropy) -> bool { + [&](const uint8_t buf[], size_t buf_len, double buf_entropy) -> bool { entropy.insert(entropy.end(), buf, buf + buf_len); entropy_estimate += buf_entropy; ++samples; @@ -93,7 +93,7 @@ class Entropy_Source_Tests : public Test comp1_size = compressed.size(); result.test_gte(comp_algo + " compressed entropy better than advertised", - compressed.size() * 8, entropy_estimate); + compressed.size() * 8, static_cast<size_t>(entropy_estimate)); } catch(std::exception& e) { |