diff options
author | Charles Giessen <charles@lunarg.com> | 2022-11-01 07:37:31 +0300 |
---|---|---|
committer | Charles Giessen <46324611+charles-lunarg@users.noreply.github.com> | 2022-11-02 00:05:40 +0300 |
commit | 3f29209dd65d52dfd5e07dd77621a718c7a4042c (patch) | |
tree | fb336067fec8a912a2f66d7d075777c6544c05ac | |
parent | a17d7fc737e650070e50655b877be1aa206a2031 (diff) |
Remove implicit fallthroughs; Add warning
Previously, cJSON used implicit fallthrough in a switch statement. Naked
fallthroughs are a common bug source, and while this use case was well
behaved, it did require disabling the compiler warnings for it. Thus,
converting it to an explicit for loop prevents unnecessary compiler
warning flags being disabled.
-rw-r--r-- | BUILD.gn | 1 | ||||
-rw-r--r-- | CMakeLists.txt | 5 | ||||
-rw-r--r-- | build-qnx/common.mk | 2 | ||||
-rw-r--r-- | loader/cJSON.c | 18 |
4 files changed, 6 insertions, 20 deletions
@@ -43,7 +43,6 @@ config("vulkan_internal_config") { cflags = [ "-Wno-conversion", "-Wno-extra-semi", - "-Wno-implicit-fallthrough", "-Wno-sign-compare", "-Wno-unreachable-code", "-Wno-unused-function", diff --git a/CMakeLists.txt b/CMakeLists.txt index 102851849..088ed209b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -295,13 +295,8 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR CMAKE_CXX_COMPILER_ID STREQUAL "Clang target_compile_options(loader_common_options INTERFACE -fno-strict-aliasing -fno-builtin-memcmp) endif() - # For GCC version 7.1 or greater, we need to disable the implicit fallthrough warning since there's no consistent way to satisfy - # all compilers until they all accept the C++17 standard if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") target_compile_options(loader_common_options INTERFACE -Wno-stringop-truncation -Wno-stringop-overflow) - if(CMAKE_CXX_COMPILER_VERSION GREATER_EQUAL 7.1) - target_compile_options(loader_common_options INTERFACE -Wimplicit-fallthrough=0) - endif() endif() if(UNIX) diff --git a/build-qnx/common.mk b/build-qnx/common.mk index d851f7f5e..a0d2a7352 100644 --- a/build-qnx/common.mk +++ b/build-qnx/common.mk @@ -31,7 +31,7 @@ include $(MKFILES_ROOT)/qtargets.mk CCFLAGS += -DVK_USE_PLATFORM_SCREEN_QNX=1 -Dvulkan_EXPORTS CCFLAGS += -Wall -Wextra -Wno-unused-parameter -Wno-missing-field-initializers CCFLAGS += -fno-strict-aliasing -fno-builtin-memcmp -Wno-stringop-truncation -CCFLAGS += -Wno-stringop-overflow -Wimplicit-fallthrough=0 -fvisibility=hidden +CCFLAGS += -Wno-stringop-overflow -fvisibility=hidden CCFLAGS += -Wpointer-arith -fPIC # Enable this if required diff --git a/loader/cJSON.c b/loader/cJSON.c index 40adcb464..be6f2655e 100644 --- a/loader/cJSON.c +++ b/loader/cJSON.c @@ -304,21 +304,13 @@ const char *parse_string(cJSON *item, const char *str) { len = 3; ptr2 += len; - switch (len) { - case 4: - *--ptr2 = ((uc | 0x80) & 0xBF); - uc >>= 6; - // fall through - case 3: - *--ptr2 = ((uc | 0x80) & 0xBF); - uc >>= 6; - // fall through - case 2: + for (size_t i = len; i > 0; i--) { + if (i == 1) { + *--ptr2 = ((unsigned char)uc | firstByteMark[len]); + } else if (i >= 2) { *--ptr2 = ((uc | 0x80) & 0xBF); uc >>= 6; - // fall through - case 1: - *--ptr2 = ((unsigned char)uc | firstByteMark[len]); + } } ptr2 += len; break; |