Skip to content

Commit bc90143

Browse files
authored
clang format on codebase (#7058)
1 parent 240be9b commit bc90143

File tree

14 files changed

+105
-136
lines changed

14 files changed

+105
-136
lines changed

include/flatbuffers/flatbuffer_builder.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,7 @@ class FlatBufferBuilder {
285285
FieldLoc fl = { off, field };
286286
buf_.scratch_push_small(fl);
287287
num_field_loc++;
288-
if (field > max_voffset_) {
289-
max_voffset_ = field;
290-
}
288+
if (field > max_voffset_) { max_voffset_ = field; }
291289
}
292290

293291
// Like PushElement, but additionally tracks the field this represents.
@@ -1074,7 +1072,7 @@ class FlatBufferBuilder {
10741072
void SwapBufAllocator(FlatBufferBuilder &other) {
10751073
buf_.swap_allocator(other.buf_);
10761074
}
1077-
1075+
10781076
/// @brief The length of a FlatBuffer file header.
10791077
static const size_t kFileIdentifierLength =
10801078
::flatbuffers::kFileIdentifierLength;

include/flatbuffers/flatbuffers.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,13 @@ struct TypeTable {
226226
};
227227

228228
// String which identifies the current version of FlatBuffers.
229-
inline const char * flatbuffers_version_string() {
229+
inline const char *flatbuffers_version_string() {
230230
return "FlatBuffers " FLATBUFFERS_STRING(FLATBUFFERS_VERSION_MAJOR) "."
231231
FLATBUFFERS_STRING(FLATBUFFERS_VERSION_MINOR) "."
232232
FLATBUFFERS_STRING(FLATBUFFERS_VERSION_REVISION);
233233
}
234234

235+
// clang-format off
235236
#define FLATBUFFERS_DEFINE_BITMASK_OPERATORS(E, T)\
236237
inline E operator | (E lhs, E rhs){\
237238
return E(T(lhs) | T(rhs));\

include/flatbuffers/flexbuffers.h

Lines changed: 46 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -371,10 +371,7 @@ void AppendToString(std::string &s, T &&v, bool keys_quoted) {
371371
class Reference {
372372
public:
373373
Reference()
374-
: data_(nullptr),
375-
parent_width_(0),
376-
byte_width_(0),
377-
type_(FBT_NULL) {}
374+
: data_(nullptr), parent_width_(0), byte_width_(0), type_(FBT_NULL) {}
378375

379376
Reference(const uint8_t *data, uint8_t parent_width, uint8_t byte_width,
380377
Type type)
@@ -1645,8 +1642,7 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
16451642
// comes at the cost of using additional memory the same size of
16461643
// the buffer being verified, so it is by default off.
16471644
std::vector<uint8_t> *reuse_tracker = nullptr,
1648-
bool _check_alignment = true,
1649-
size_t max_depth = 64)
1645+
bool _check_alignment = true, size_t max_depth = 64)
16501646
: buf_(buf),
16511647
size_(buf_len),
16521648
depth_(0),
@@ -1689,35 +1685,33 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
16891685
auto o = static_cast<size_t>(p - buf_);
16901686
return VerifyBefore(o, len);
16911687
}
1692-
1688+
16931689
bool VerifyByteWidth(size_t width) {
16941690
return Check(width == 1 || width == 2 || width == 4 || width == 8);
16951691
}
16961692

1697-
bool VerifyType(int type) {
1698-
return Check(type >= 0 && type < FBT_MAX_TYPE);
1699-
}
1693+
bool VerifyType(int type) { return Check(type >= 0 && type < FBT_MAX_TYPE); }
17001694

17011695
bool VerifyOffset(uint64_t off, const uint8_t *p) {
17021696
return Check(off <= static_cast<uint64_t>(size_)) &&
1703-
off <= static_cast<uint64_t>(p - buf_);
1697+
off <= static_cast<uint64_t>(p - buf_);
17041698
}
17051699

17061700
bool VerifyAlignment(const uint8_t *p, size_t size) const {
17071701
auto o = static_cast<size_t>(p - buf_);
17081702
return Check((o & (size - 1)) == 0 || !check_alignment_);
17091703
}
17101704

1711-
// Macro, since we want to escape from parent function & use lazy args.
1712-
#define FLEX_CHECK_VERIFIED(P, PACKED_TYPE) \
1713-
if (reuse_tracker_) { \
1714-
auto packed_type = PACKED_TYPE; \
1715-
auto existing = (*reuse_tracker_)[P - buf_]; \
1716-
if (existing == packed_type) return true; \
1717-
/* Fail verification if already set with different type! */ \
1718-
if (!Check(existing == 0)) return false; \
1719-
(*reuse_tracker_)[P - buf_] = packed_type; \
1720-
}
1705+
// Macro, since we want to escape from parent function & use lazy args.
1706+
#define FLEX_CHECK_VERIFIED(P, PACKED_TYPE) \
1707+
if (reuse_tracker_) { \
1708+
auto packed_type = PACKED_TYPE; \
1709+
auto existing = (*reuse_tracker_)[P - buf_]; \
1710+
if (existing == packed_type) return true; \
1711+
/* Fail verification if already set with different type! */ \
1712+
if (!Check(existing == 0)) return false; \
1713+
(*reuse_tracker_)[P - buf_] = packed_type; \
1714+
}
17211715

17221716
bool VerifyVector(Reference r, const uint8_t *p, Type elem_type) {
17231717
// Any kind of nesting goes thru this function, so guard against that
@@ -1727,19 +1721,19 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
17271721
if (!Check(depth_ <= max_depth_ && num_vectors_ <= max_vectors_))
17281722
return false;
17291723
auto size_byte_width = r.byte_width_;
1730-
FLEX_CHECK_VERIFIED(p, PackedType(Builder::WidthB(size_byte_width), r.type_));
1731-
if (!VerifyBeforePointer(p, size_byte_width))
1732-
return false;
1724+
FLEX_CHECK_VERIFIED(p,
1725+
PackedType(Builder::WidthB(size_byte_width), r.type_));
1726+
if (!VerifyBeforePointer(p, size_byte_width)) return false;
17331727
auto sized = Sized(p, size_byte_width);
17341728
auto num_elems = sized.size();
1735-
auto elem_byte_width =
1736-
r.type_ == FBT_STRING || r.type_ == FBT_BLOB ? uint8_t(1) : r.byte_width_;
1729+
auto elem_byte_width = r.type_ == FBT_STRING || r.type_ == FBT_BLOB
1730+
? uint8_t(1)
1731+
: r.byte_width_;
17371732
auto max_elems = SIZE_MAX / elem_byte_width;
17381733
if (!Check(num_elems < max_elems))
17391734
return false; // Protect against byte_size overflowing.
17401735
auto byte_size = num_elems * elem_byte_width;
1741-
if (!VerifyFromPointer(p, byte_size))
1742-
return false;
1736+
if (!VerifyFromPointer(p, byte_size)) return false;
17431737
if (elem_type == FBT_NULL) {
17441738
// Verify type bytes after the vector.
17451739
if (!VerifyFromPointer(p + byte_size, num_elems)) return false;
@@ -1760,28 +1754,25 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
17601754
bool VerifyKeys(const uint8_t *p, uint8_t byte_width) {
17611755
// The vector part of the map has already been verified.
17621756
const size_t num_prefixed_fields = 3;
1763-
if (!VerifyBeforePointer(p, byte_width * num_prefixed_fields))
1764-
return false;
1757+
if (!VerifyBeforePointer(p, byte_width * num_prefixed_fields)) return false;
17651758
p -= byte_width * num_prefixed_fields;
17661759
auto off = ReadUInt64(p, byte_width);
1767-
if (!VerifyOffset(off, p))
1768-
return false;
1760+
if (!VerifyOffset(off, p)) return false;
17691761
auto key_byte_with =
1770-
static_cast<uint8_t>(ReadUInt64(p + byte_width, byte_width));
1771-
if (!VerifyByteWidth(key_byte_with))
1772-
return false;
1762+
static_cast<uint8_t>(ReadUInt64(p + byte_width, byte_width));
1763+
if (!VerifyByteWidth(key_byte_with)) return false;
17731764
return VerifyVector(Reference(p, byte_width, key_byte_with, FBT_VECTOR_KEY),
17741765
p - off, FBT_KEY);
17751766
}
17761767

1777-
bool VerifyKey(const uint8_t* p) {
1768+
bool VerifyKey(const uint8_t *p) {
17781769
FLEX_CHECK_VERIFIED(p, PackedType(BIT_WIDTH_8, FBT_KEY));
17791770
while (p < buf_ + size_)
17801771
if (*p++) return true;
17811772
return false;
17821773
}
17831774

1784-
#undef FLEX_CHECK_VERIFIED
1775+
#undef FLEX_CHECK_VERIFIED
17851776

17861777
bool VerifyTerminator(const String &s) {
17871778
return VerifyFromPointer(reinterpret_cast<const uint8_t *>(s.c_str()),
@@ -1799,37 +1790,26 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
17991790
}
18001791
// All remaining types are an offset.
18011792
auto off = ReadUInt64(r.data_, r.parent_width_);
1802-
if (!VerifyOffset(off, r.data_))
1803-
return false;
1793+
if (!VerifyOffset(off, r.data_)) return false;
18041794
auto p = r.Indirect();
1805-
if (!VerifyAlignment(p, r.byte_width_))
1806-
return false;
1795+
if (!VerifyAlignment(p, r.byte_width_)) return false;
18071796
switch (r.type_) {
18081797
case FBT_INDIRECT_INT:
18091798
case FBT_INDIRECT_UINT:
1810-
case FBT_INDIRECT_FLOAT:
1811-
return VerifyFromPointer(p, r.byte_width_);
1812-
case FBT_KEY:
1813-
return VerifyKey(p);
1799+
case FBT_INDIRECT_FLOAT: return VerifyFromPointer(p, r.byte_width_);
1800+
case FBT_KEY: return VerifyKey(p);
18141801
case FBT_MAP:
1815-
return VerifyVector(r, p, FBT_NULL) &&
1816-
VerifyKeys(p, r.byte_width_);
1817-
case FBT_VECTOR:
1818-
return VerifyVector(r, p, FBT_NULL);
1819-
case FBT_VECTOR_INT:
1820-
return VerifyVector(r, p, FBT_INT);
1802+
return VerifyVector(r, p, FBT_NULL) && VerifyKeys(p, r.byte_width_);
1803+
case FBT_VECTOR: return VerifyVector(r, p, FBT_NULL);
1804+
case FBT_VECTOR_INT: return VerifyVector(r, p, FBT_INT);
18211805
case FBT_VECTOR_BOOL:
1822-
case FBT_VECTOR_UINT:
1823-
return VerifyVector(r, p, FBT_UINT);
1824-
case FBT_VECTOR_FLOAT:
1825-
return VerifyVector(r, p, FBT_FLOAT);
1826-
case FBT_VECTOR_KEY:
1827-
return VerifyVector(r, p, FBT_KEY);
1806+
case FBT_VECTOR_UINT: return VerifyVector(r, p, FBT_UINT);
1807+
case FBT_VECTOR_FLOAT: return VerifyVector(r, p, FBT_FLOAT);
1808+
case FBT_VECTOR_KEY: return VerifyVector(r, p, FBT_KEY);
18281809
case FBT_VECTOR_STRING_DEPRECATED:
18291810
// Use of FBT_KEY here intentional, see elsewhere.
18301811
return VerifyVector(r, p, FBT_KEY);
1831-
case FBT_BLOB:
1832-
return VerifyVector(r, p, FBT_UINT);
1812+
case FBT_BLOB: return VerifyVector(r, p, FBT_UINT);
18331813
case FBT_STRING:
18341814
return VerifyVector(r, p, FBT_UINT) &&
18351815
VerifyTerminator(String(p, r.byte_width_));
@@ -1844,12 +1824,10 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
18441824
case FBT_VECTOR_FLOAT4: {
18451825
uint8_t len = 0;
18461826
auto vtype = ToFixedTypedVectorElementType(r.type_, &len);
1847-
if (!VerifyType(vtype))
1848-
return false;
1827+
if (!VerifyType(vtype)) return false;
18491828
return VerifyFromPointer(p, r.byte_width_ * len);
18501829
}
1851-
default:
1852-
return false;
1830+
default: return false;
18531831
}
18541832
}
18551833

@@ -1859,8 +1837,7 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
18591837
auto end = buf_ + size_;
18601838
auto byte_width = *--end;
18611839
auto packed_type = *--end;
1862-
return VerifyByteWidth(byte_width) &&
1863-
Check(end - buf_ >= byte_width) &&
1840+
return VerifyByteWidth(byte_width) && Check(end - buf_ >= byte_width) &&
18641841
VerifyRef(Reference(end - byte_width, byte_width, packed_type));
18651842
}
18661843

@@ -1875,24 +1852,23 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
18751852
std::vector<uint8_t> *reuse_tracker_;
18761853
};
18771854

1878-
// Utility function that contructs the Verifier for you, see above for parameters.
1855+
// Utility function that contructs the Verifier for you, see above for
1856+
// parameters.
18791857
inline bool VerifyBuffer(const uint8_t *buf, size_t buf_len,
18801858
std::vector<uint8_t> *reuse_tracker = nullptr) {
18811859
Verifier verifier(buf, buf_len, reuse_tracker);
18821860
return verifier.VerifyBuffer();
18831861
}
18841862

1885-
18861863
#ifdef FLATBUFFERS_H_
18871864
// This is a verifier utility function that works together with the
18881865
// FlatBuffers verifier, which should only be present if flatbuffer.h
18891866
// has been included (which it typically is in generated code).
18901867
inline bool VerifyNestedFlexBuffer(const flatbuffers::Vector<uint8_t> *nv,
18911868
flatbuffers::Verifier &verifier) {
18921869
if (!nv) return true;
1893-
return verifier.Check(
1894-
flexbuffers::VerifyBuffer(nv->data(), nv->size(),
1895-
verifier.GetFlexReuseTracker()));
1870+
return verifier.Check(flexbuffers::VerifyBuffer(
1871+
nv->data(), nv->size(), verifier.GetFlexReuseTracker()));
18961872
}
18971873
#endif
18981874

include/flatbuffers/table.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -112,18 +112,19 @@ class Table {
112112

113113
// Verify a particular field.
114114
template<typename T>
115-
bool VerifyField(const Verifier &verifier, voffset_t field, size_t align) const {
115+
bool VerifyField(const Verifier &verifier, voffset_t field,
116+
size_t align) const {
116117
// Calling GetOptionalFieldOffset should be safe now thanks to
117118
// VerifyTable().
118119
auto field_offset = GetOptionalFieldOffset(field);
119120
// Check the actual field.
120-
return !field_offset ||
121-
verifier.VerifyField<T>(data_, field_offset, align);
121+
return !field_offset || verifier.VerifyField<T>(data_, field_offset, align);
122122
}
123123

124124
// VerifyField for required fields.
125125
template<typename T>
126-
bool VerifyFieldRequired(const Verifier &verifier, voffset_t field, size_t align) const {
126+
bool VerifyFieldRequired(const Verifier &verifier, voffset_t field,
127+
size_t align) const {
127128
auto field_offset = GetOptionalFieldOffset(field);
128129
return verifier.Check(field_offset != 0) &&
129130
verifier.VerifyField<T>(data_, field_offset, align);

include/flatbuffers/util.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@
1717
#ifndef FLATBUFFERS_UTIL_H_
1818
#define FLATBUFFERS_UTIL_H_
1919

20-
#include <errno.h>
2120
#include <ctype.h>
21+
#include <errno.h>
2222

2323
#include "flatbuffers/base.h"
2424
#include "flatbuffers/stl_emulation.h"
2525

2626
#ifndef FLATBUFFERS_PREFER_PRINTF
27-
# include <sstream>
2827
# include <iomanip>
28+
# include <sstream>
2929
#else // FLATBUFFERS_PREFER_PRINTF
3030
# include <float.h>
3131
# include <stdio.h>

include/flatbuffers/verifier.h

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -81,14 +81,15 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
8181
}
8282

8383
// Verify relative to a known-good base pointer.
84-
bool VerifyFieldStruct(const uint8_t *base, voffset_t elem_off, size_t elem_len,
85-
size_t align) const {
84+
bool VerifyFieldStruct(const uint8_t *base, voffset_t elem_off,
85+
size_t elem_len, size_t align) const {
8686
auto f = static_cast<size_t>(base - buf_) + elem_off;
8787
return VerifyAlignment(f, align) && Verify(f, elem_len);
8888
}
8989

9090
template<typename T>
91-
bool VerifyField(const uint8_t *base, voffset_t elem_off, size_t align) const {
91+
bool VerifyField(const uint8_t *base, voffset_t elem_off,
92+
size_t align) const {
9293
auto f = static_cast<size_t>(base - buf_) + elem_off;
9394
return VerifyAlignment(f, align) && Verify(f, sizeof(T));
9495
}
@@ -259,9 +260,7 @@ class Verifier FLATBUFFERS_FINAL_CLASS {
259260
// clang-format on
260261
}
261262

262-
std::vector<uint8_t> *GetFlexReuseTracker() {
263-
return flex_reuse_tracker_;
264-
}
263+
std::vector<uint8_t> *GetFlexReuseTracker() { return flex_reuse_tracker_; }
265264

266265
void SetFlexReuseTracker(std::vector<uint8_t> *rt) {
267266
flex_reuse_tracker_ = rt;

0 commit comments

Comments
 (0)