1
0
mirror of https://github.com/biergaizi/codecrypt synced 2024-06-16 11:58:16 +00:00

sc.h: correct access violation in load_key_vector(), close #2.

In load_key_vector(), the program passes a std::vector<byte> to
a C-style function, load_key (const byte*begin, const byte*end)
by creating references

    load_key (& (K[0]), & (K[K.size()]));

However, accessing the one-past-the-last element in a std::vector
via [] is not allowed in C++, it triggers an assertion failure.

    Assertion '__builtin_expect(__n < this->size(), true)' failed.

In this commit, we use K.data() and K.data() + K.size() to expose
the underlying pointers and pass them to the C function.

Signed-off-by: Tom Li <tomli@tomli.me>
This commit is contained in:
Tom Li 2019-01-02 11:37:48 +08:00
parent 4441f8e514
commit 7021f6c734
No known key found for this signature in database
GPG Key ID: FAD3EB05E88E8D6D

@ -50,7 +50,7 @@ public:
}
void load_key_vector (const std::vector<byte>&K) {
load_key (& (K[0]), & (K[K.size()]));
load_key (K.data(), K.data() + K.size());
}
typedef std::map<std::string, factoryof<streamcipher>*> suite_t;