From 3ca84ef40f3f45d4e13e36651bde13090dc4051a Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Sun, 27 Jul 2014 20:06:32 +0300 Subject: [PATCH] Some minor changes in bf stream. --- stglibs/crypto.lib/bfstream.cpp | 3 ++- tests/test_bfstream.cpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/stglibs/crypto.lib/bfstream.cpp b/stglibs/crypto.lib/bfstream.cpp index 4f376c5d..24aa7e10 100644 --- a/stglibs/crypto.lib/bfstream.cpp +++ b/stglibs/crypto.lib/bfstream.cpp @@ -26,6 +26,7 @@ class COMMON m_proc(proc) { InitContext(key.c_str(), key.length(), &m_ctx); + memset(m_buffer, 0, sizeof(m_buffer)); } void Put(const void * data, size_t size, bool last) @@ -35,7 +36,7 @@ class COMMON { memcpy(m_ptr, data, sizeof(m_buffer) - dataSize); // Fill buffer size -= sizeof(m_buffer) - dataSize; // Adjust size - data += sizeof(m_buffer) - dataSize; // Adjust data pointer + data = static_cast(data) + sizeof(m_buffer) - dataSize; // Adjust data pointer m_proc(m_buffer, m_buffer, sizeof(m_buffer), &m_ctx); // Process m_callback(m_buffer, sizeof(m_buffer), m_data); // Consume m_ptr = m_buffer; diff --git a/tests/test_bfstream.cpp b/tests/test_bfstream.cpp index 18884d6d..595301b2 100644 --- a/tests/test_bfstream.cpp +++ b/tests/test_bfstream.cpp @@ -122,6 +122,7 @@ namespace tut STG::ENCRYPT_STREAM estream("pr7Hhen", Callback, &tracker); std::string source = "This is a test long string for checking stream encryption/decryption. \"abcdefghijklmnopqrstuvwxyz 0123456789 ABCDEFGHIJKLMNOPQRSTUVWXYZ\""; char buffer[source.length() + 9]; + memset(buffer, 0, sizeof(buffer)); estream.Put(source.c_str(), source.length() + 1, true); ensure("Encryption long string LastSize()", tracker.LastSize() >= source.length() + 1); -- 2.44.2