mirror of
https://github.com/Zygo/bees.git
synced 2025-05-17 21:35:45 +02:00
bytevector: validate length in get<T>()
Don't allow a pointer to T to be taken from a ByteVector that is not at least sizeof(T) bytes long. Signed-off-by: Zygo Blaxell <bees@furryterror.org>
This commit is contained in:
parent
148cc03060
commit
152e69a6d1
@ -1,6 +1,8 @@
|
||||
#ifndef _CRUCIBLE_BYTEVECTOR_H_
|
||||
#define _CRUCIBLE_BYTEVECTOR_H_
|
||||
|
||||
#include <crucible/error.h>
|
||||
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
#include <ostream>
|
||||
@ -69,6 +71,7 @@ namespace crucible {
|
||||
T*
|
||||
ByteVector::get() const
|
||||
{
|
||||
THROW_CHECK2(out_of_range, size(), sizeof(T), size() >= sizeof(T));
|
||||
return reinterpret_cast<T*>(data());
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user