various fixes for google merge

This commit is contained in:
Derek Bailey
2022-04-18 21:15:35 -07:00
parent 6e0e79f24f
commit 70002dc5ca
3 changed files with 10 additions and 5 deletions

View File

@@ -330,7 +330,7 @@ typedef uintmax_t largest_scalar_t;
// We support aligning the contents of buffers up to this size. // We support aligning the contents of buffers up to this size.
#ifndef FLATBUFFERS_MAX_ALIGNMENT #ifndef FLATBUFFERS_MAX_ALIGNMENT
#define FLATBUFFERS_MAX_ALIGNMENT 16 #define FLATBUFFERS_MAX_ALIGNMENT 32
#endif #endif
/// @brief The length of a FlatBuffer file header. /// @brief The length of a FlatBuffer file header.

View File

@@ -442,6 +442,7 @@ class FlatBufferBuilder {
// Aligns such that when "len" bytes are written, an object can be written // Aligns such that when "len" bytes are written, an object can be written
// after it with "alignment" without padding. // after it with "alignment" without padding.
void PreAlign(size_t len, size_t alignment) { void PreAlign(size_t len, size_t alignment) {
if (len == 0) return;
TrackMinAlign(alignment); TrackMinAlign(alignment);
buf_.fill(PaddingBytes(GetSize() + len, alignment)); buf_.fill(PaddingBytes(GetSize() + len, alignment));
} }
@@ -600,12 +601,14 @@ class FlatBufferBuilder {
// This is useful when storing a nested_flatbuffer in a vector of bytes, // This is useful when storing a nested_flatbuffer in a vector of bytes,
// or when storing SIMD floats, etc. // or when storing SIMD floats, etc.
void ForceVectorAlignment(size_t len, size_t elemsize, size_t alignment) { void ForceVectorAlignment(size_t len, size_t elemsize, size_t alignment) {
if (len == 0) return;
FLATBUFFERS_ASSERT(VerifyAlignmentRequirements(alignment)); FLATBUFFERS_ASSERT(VerifyAlignmentRequirements(alignment));
PreAlign(len * elemsize, alignment); PreAlign(len * elemsize, alignment);
} }
// Similar to ForceVectorAlignment but for String fields. // Similar to ForceVectorAlignment but for String fields.
void ForceStringAlignment(size_t len, size_t alignment) { void ForceStringAlignment(size_t len, size_t alignment) {
if (len == 0) return;
FLATBUFFERS_ASSERT(VerifyAlignmentRequirements(alignment)); FLATBUFFERS_ASSERT(VerifyAlignmentRequirements(alignment));
PreAlign((len + 1) * sizeof(char), alignment); PreAlign((len + 1) * sizeof(char), alignment);
} }

View File

@@ -1102,8 +1102,9 @@ CheckedError Parser::ParseAnyValue(Value &val, FieldDef *field,
uint8_t enum_idx; uint8_t enum_idx;
if (vector_of_union_types) { if (vector_of_union_types) {
if (vector_of_union_types->size() <= count) if (vector_of_union_types->size() <= count)
return Error("union types vector smaller than union values vector" return Error(
" for: " + field->name); "union types vector smaller than union values vector for: " +
field->name);
enum_idx = vector_of_union_types->Get(count); enum_idx = vector_of_union_types->Get(count);
} else { } else {
ECHECK(atot(constant.c_str(), *this, &enum_idx)); ECHECK(atot(constant.c_str(), *this, &enum_idx));
@@ -2884,7 +2885,8 @@ CheckedError Parser::ParseProtoFields(StructDef *struct_def, bool isextend,
if (key == "default") { if (key == "default") {
// Temp: skip non-numeric and non-boolean defaults (enums). // Temp: skip non-numeric and non-boolean defaults (enums).
auto numeric = strpbrk(val.c_str(), "0123456789-+."); auto numeric = strpbrk(val.c_str(), "0123456789-+.");
if (IsScalar(type.base_type) && numeric == val.c_str()) { if (IsScalar(type.base_type) &&
(numeric == val.c_str() || val == "inf" || val == "-inf")) {
field->value.constant = val; field->value.constant = val;
} else if (val == "true") { } else if (val == "true") {
field->value.constant = val; field->value.constant = val;
@@ -3255,7 +3257,6 @@ CheckedError Parser::ParseRoot(const char *source, const char **include_paths,
} }
// Parse JSON object only if the scheme has been parsed. // Parse JSON object only if the scheme has been parsed.
if (token_ == '{') { ECHECK(DoParseJson()); } if (token_ == '{') { ECHECK(DoParseJson()); }
EXPECT(kTokenEof);
return NoError(); return NoError();
} }
@@ -3423,6 +3424,7 @@ CheckedError Parser::DoParse(const char *source, const char **include_paths,
ECHECK(ParseDecl(source_filename)); ECHECK(ParseDecl(source_filename));
} }
} }
EXPECT(kTokenEof);
if (opts.warnings_as_errors && has_warning_) { if (opts.warnings_as_errors && has_warning_) {
return Error("treating warnings as errors, failed due to above warnings"); return Error("treating warnings as errors, failed due to above warnings");
} }