Skip to content

Commit

Permalink
various fixes for google merge
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaileychess committed Apr 19, 2022
1 parent 6e0e79f commit 70002dc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
2 changes: 1 addition & 1 deletion include/flatbuffers/base.h
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ typedef uintmax_t largest_scalar_t;

// We support aligning the contents of buffers up to this size.
#ifndef FLATBUFFERS_MAX_ALIGNMENT
#define FLATBUFFERS_MAX_ALIGNMENT 16
#define FLATBUFFERS_MAX_ALIGNMENT 32
#endif

/// @brief The length of a FlatBuffer file header.
Expand Down
3 changes: 3 additions & 0 deletions include/flatbuffers/flatbuffer_builder.h
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,7 @@ class FlatBufferBuilder {
// Aligns such that when "len" bytes are written, an object can be written
// after it with "alignment" without padding.
void PreAlign(size_t len, size_t alignment) {
if (len == 0) return;
TrackMinAlign(alignment);
buf_.fill(PaddingBytes(GetSize() + len, alignment));
}
Expand Down Expand Up @@ -600,12 +601,14 @@ class FlatBufferBuilder {
// This is useful when storing a nested_flatbuffer in a vector of bytes,
// or when storing SIMD floats, etc.
void ForceVectorAlignment(size_t len, size_t elemsize, size_t alignment) {
if (len == 0) return;
FLATBUFFERS_ASSERT(VerifyAlignmentRequirements(alignment));
PreAlign(len * elemsize, alignment);
}

// Similar to ForceVectorAlignment but for String fields.
void ForceStringAlignment(size_t len, size_t alignment) {
if (len == 0) return;
FLATBUFFERS_ASSERT(VerifyAlignmentRequirements(alignment));
PreAlign((len + 1) * sizeof(char), alignment);
}
Expand Down
10 changes: 6 additions & 4 deletions src/idl_parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1102,8 +1102,9 @@ CheckedError Parser::ParseAnyValue(Value &val, FieldDef *field,
uint8_t enum_idx;
if (vector_of_union_types) {
if (vector_of_union_types->size() <= count)
return Error("union types vector smaller than union values vector"
" for: " + field->name);
return Error(
"union types vector smaller than union values vector for: " +
field->name);
enum_idx = vector_of_union_types->Get(count);
} else {
ECHECK(atot(constant.c_str(), *this, &enum_idx));
Expand Down Expand Up @@ -2884,7 +2885,8 @@ CheckedError Parser::ParseProtoFields(StructDef *struct_def, bool isextend,
if (key == "default") {
// Temp: skip non-numeric and non-boolean defaults (enums).
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;
} else if (val == "true") {
field->value.constant = val;
Expand Down Expand Up @@ -3255,7 +3257,6 @@ CheckedError Parser::ParseRoot(const char *source, const char **include_paths,
}
// Parse JSON object only if the scheme has been parsed.
if (token_ == '{') { ECHECK(DoParseJson()); }
EXPECT(kTokenEof);
return NoError();
}

Expand Down Expand Up @@ -3423,6 +3424,7 @@ CheckedError Parser::DoParse(const char *source, const char **include_paths,
ECHECK(ParseDecl(source_filename));
}
}
EXPECT(kTokenEof);
if (opts.warnings_as_errors && has_warning_) {
return Error("treating warnings as errors, failed due to above warnings");
}
Expand Down

0 comments on commit 70002dc

Please sign in to comment.