diff options
author | Charles Giessen <charles@lunarg.com> | 2022-10-31 22:37:31 -0600 |
---|---|---|
committer | Charles Giessen <46324611+charles-lunarg@users.noreply.github.com> | 2022-11-01 15:05:40 -0600 |
commit | 3f29209dd65d52dfd5e07dd77621a718c7a4042c (patch) | |
tree | fb336067fec8a912a2f66d7d075777c6544c05ac | |
parent | a17d7fc737e650070e50655b877be1aa206a2031 (diff) | |
download | Vulkan-Loader-3f29209dd65d52dfd5e07dd77621a718c7a4042c.tar.gz Vulkan-Loader-3f29209dd65d52dfd5e07dd77621a718c7a4042c.tar.bz2 Vulkan-Loader-3f29209dd65d52dfd5e07dd77621a718c7a4042c.zip |
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 10285184..088ed209 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 d851f7f5..a0d2a735 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 40adcb46..be6f2655 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; |