Skip to content

Commit 1d4de83

Browse files
committed
TOLERATE_MISALIGNED -> ENFORCE_ALIGNED
1 parent f86387b commit 1d4de83

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

CMakeLists.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,11 @@ option (FLATCC_TRACE_VERIFY
7878
"assert on verify failure in runtime lib" OFF)
7979

8080
# Some producers allow empty vectors to be misaligned.
81-
# The following setting will cause the verifier to check for an
82-
# empty vector before checking alignment of the vector's elements.
83-
option (FLATCC_TOLERATE_MISALIGNED_EMPTY_VECTORS
84-
"don't fail verification if empty vectors are misaligned" OFF)
81+
# The following setting will cause the verifier to require the index 0
82+
# position to be element aligned even if the vector is empty (otherwise that
83+
# position is only required to be aligned to the preceding size field).
84+
option (FLATCC_ENFORCE_ALIGNED_EMPTY_VECTORS
85+
"verify includes full alignment check for empty vectors" OFF)
8586

8687
# Reflection is the compilers ability to generate binary schema output
8788
# (.bfbs files). This requires using generated code from
@@ -147,8 +148,8 @@ if (FLATCC_TRACE_VERIFY)
147148
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFLATCC_TRACE_VERIFY=1")
148149
endif()
149150

150-
if (FLATCC_TOLERATE_MISALIGNED_EMPTY_VECTORS)
151-
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFLATCC_TOLERATE_MISALIGNED_EMPTY_VECTORS=1")
151+
if (FLATCC_ENFORCE_ALIGNED_EMPTY_VECTORS)
152+
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DFLATCC_ENFORCE_ALIGNED_EMPTY_VECTORS=1")
152153
endif()
153154

154155

include/flatcc/flatcc_rtconfig.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,12 @@ extern "C" {
6565

6666
/*
6767
* Some producers allow empty vectors to be misaligned.
68-
* The following setting will cause the verifier to check for an
69-
* empty vector before checking alignment of the vector's elements.
68+
* The following setting will cause the verifier to require the index 0
69+
* position to be element aligned even if the vector is empty (otherwise that
70+
* position is only required to be aligned to the preceding size field).
7071
*/
71-
#if !defined(FLATCC_TOLERATE_MISALIGNED_EMPTY_VECTORS)
72-
#define FLATCC_TOLERATE_MISALIGNED_EMPTY_VECTORS 0
72+
#if !defined(FLATCC_ENFORCE_ALIGNED_EMPTY_VECTORS)
73+
#define FLATCC_ENFORCE_ALIGNED_EMPTY_VECTORS 0
7374
#endif
7475

7576
/*

src/runtime/verifier.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,11 @@ static inline int verify_vector(const void *buf, uoffset_t end, uoffset_t base,
270270
n = read_uoffset(buf, base);
271271
base += offset_size;
272272

273-
#if FLATCC_TOLERATE_MISALIGNED_EMPTY_VECTORS
273+
#if !FLATCC_ENFORCE_ALIGNED_EMPTY_VECTORS
274274
/* This is due to incorrect buffers from other builders than cannot easily be ignored. */
275275
align = n == 0 ? uoffset_size : align;
276276
#endif
277-
align = align < uoffset_size ? uoffset_size : align;
278-
verify(!(base & (align - 1u)),flatcc_verify_error_vector_header_out_of_range_or_unaligned);
279-
277+
verify(!(base & ((align - 1u) | (uoffset_size - 1u))), flatcc_verify_error_vector_header_out_of_range_or_unaligned);
280278
/* `n * elem_size` can overflow uncontrollably otherwise. */
281279
verify(n <= max_count, flatcc_verify_error_vector_count_exceeds_representable_vector_size);
282280
verify(end - base >= n * elem_size, flatcc_verify_error_vector_out_of_range);

0 commit comments

Comments
 (0)