mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-28 14:30:01 +00:00
Enables to compile flatbuffer_builder.h with strict settings -Wconversion -Wsign-conversion. Also, add asserts to verify the conversions.
This commit is contained in:
@@ -45,8 +45,9 @@ inline voffset_t FieldIndexToOffset(voffset_t field_id) {
|
|||||||
// Should correspond to what EndTable() below builds up.
|
// Should correspond to what EndTable() below builds up.
|
||||||
const voffset_t fixed_fields =
|
const voffset_t fixed_fields =
|
||||||
2 * sizeof(voffset_t); // Vtable size and Object Size.
|
2 * sizeof(voffset_t); // Vtable size and Object Size.
|
||||||
return fixed_fields + field_id * sizeof(voffset_t);
|
size_t offset = fixed_fields + field_id * sizeof(voffset_t);
|
||||||
}
|
FLATBUFFERS_ASSERT(offset < std::numeric_limits<voffset_t>::max());
|
||||||
|
return static_cast<voffset_t>(offset);}
|
||||||
|
|
||||||
template<typename T, typename Alloc = std::allocator<T>>
|
template<typename T, typename Alloc = std::allocator<T>>
|
||||||
const T *data(const std::vector<T, Alloc> &v) {
|
const T *data(const std::vector<T, Alloc> &v) {
|
||||||
@@ -879,7 +880,9 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
|
|||||||
/// where the vector is stored.
|
/// where the vector is stored.
|
||||||
template<class It>
|
template<class It>
|
||||||
Offset<Vector<Offset<String>>> CreateVectorOfStrings(It begin, It end) {
|
Offset<Vector<Offset<String>>> CreateVectorOfStrings(It begin, It end) {
|
||||||
auto size = std::distance(begin, end);
|
auto distance = std::distance(begin, end);
|
||||||
|
FLATBUFFERS_ASSERT(distance >= 0);
|
||||||
|
auto size = static_cast<size_t>(distance);
|
||||||
auto scratch_buffer_usage = size * sizeof(Offset<String>);
|
auto scratch_buffer_usage = size * sizeof(Offset<String>);
|
||||||
// If there is not enough space to store the offsets, there definitely won't
|
// If there is not enough space to store the offsets, there definitely won't
|
||||||
// be enough space to store all the strings. So ensuring space for the
|
// be enough space to store all the strings. So ensuring space for the
|
||||||
@@ -889,7 +892,7 @@ template<bool Is64Aware = false> class FlatBufferBuilderImpl {
|
|||||||
buf_.scratch_push_small(CreateString(*it));
|
buf_.scratch_push_small(CreateString(*it));
|
||||||
}
|
}
|
||||||
StartVector<Offset<String>>(size);
|
StartVector<Offset<String>>(size);
|
||||||
for (auto i = 1; i <= size; i++) {
|
for (size_t i = 1; i <= size; i++) {
|
||||||
// Note we re-evaluate the buf location each iteration to account for any
|
// Note we re-evaluate the buf location each iteration to account for any
|
||||||
// underlying buffer resizing that may occur.
|
// underlying buffer resizing that may occur.
|
||||||
PushElement(*reinterpret_cast<Offset<String> *>(
|
PushElement(*reinterpret_cast<Offset<String> *>(
|
||||||
|
|||||||
Reference in New Issue
Block a user