From: Maxim Mamontov Date: Sun, 27 Jul 2014 17:06:32 +0000 (+0300) Subject: Some minor changes in bf stream. X-Git-Url: https://git.stg.codes/stg.git/commitdiff_plain/3f023a72d0eedd982ba16401fbdff63dc5dddd4d?ds=inline;hp=91002d861d8e0729e84f9ef65a19001d515d7dbe Some minor changes in bf stream. --- 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);