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.
cflags = [
"-Wno-conversion",
"-Wno-extra-semi",
- "-Wno-implicit-fallthrough",
"-Wno-sign-compare",
"-Wno-unreachable-code",
"-Wno-unused-function",
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)
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
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;