mirror of
https://github.com/Zygo/bees.git
synced 2025-05-18 05:45: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_
|
#ifndef _CRUCIBLE_BYTEVECTOR_H_
|
||||||
#define _CRUCIBLE_BYTEVECTOR_H_
|
#define _CRUCIBLE_BYTEVECTOR_H_
|
||||||
|
|
||||||
|
#include <crucible/error.h>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
@ -69,6 +71,7 @@ namespace crucible {
|
|||||||
T*
|
T*
|
||||||
ByteVector::get() const
|
ByteVector::get() const
|
||||||
{
|
{
|
||||||
|
THROW_CHECK2(out_of_range, size(), sizeof(T), size() >= sizeof(T));
|
||||||
return reinterpret_cast<T*>(data());
|
return reinterpret_cast<T*>(data());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user