Skip to content

Commit

Permalink
Add clang debug sanitizer flag and fix related warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
mikkelfj committed Oct 24, 2023
1 parent d533710 commit 0e925e1
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
- Fix regression where empty namespace in schema does not reset root scope
correctly in parser (#265).
- Fix lexer checks that breaks with UTF-8, notably UTF-8 schema comments (#267).
- Fix UB in memcpy(p, 0, 0) by initializing scope prefix (mostly to silence sanitizers).
- Add sanitizer flag for clang debug and related warnings (input from several PRs incl. #237)

## [0.6.1]

Expand Down
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ if (CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT "${CMAKE_CXX_SIMULATE_ID}" STREQ
if (FLATCC_IGNORE_CONST_COND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-tautological-constant-out-of-range-compare")
endif()
if (CMAKE_BUILD_TYPE MATCHES Debug)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fsanitize=undefined")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fsanitize=undefined")
endif()
# Suppress warning relaxed in clang-6, see https://reviews.llvm.org/D28148
if (CMAKE_C_COMPILER_VERSION VERSION_LESS 6)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wno-missing-field-initializers")
Expand Down
1 change: 0 additions & 1 deletion src/compiler/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -1270,7 +1270,6 @@ static void push_token(fb_parser_t *P, long id, const char *first, const char *l
size_t offset;
fb_token_t *t;

P->te = P->ts + P->tcapacity;
if (P->token == P->te) {
offset = (size_t)(P->token - P->ts);
P->tcapacity = P->tcapacity ? 2 * P->tcapacity : 1024;
Expand Down
2 changes: 1 addition & 1 deletion src/runtime/builder.c
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ int flatcc_builder_default_alloc(void *alloc_context, iovec_t *b, size_t request
return 0;
}

#define T_ptr(base, pos) ((void *)((uint8_t *)(base) + (uoffset_t)(pos)))
#define T_ptr(base, pos) ((void *)((size_t)(base) + (size_t)(pos)))
#define ds_ptr(pos) (T_ptr(B->buffers[flatcc_builder_alloc_ds].iov_base, (pos)))
#define vs_ptr(pos) (T_ptr(B->buffers[flatcc_builder_alloc_vs].iov_base, (pos)))
#define pl_ptr(pos) (T_ptr(B->buffers[flatcc_builder_alloc_pl].iov_base, (pos)))
Expand Down

0 comments on commit 0e925e1

Please sign in to comment.