From a99c14166f1958b243dd62bc12bc6a983b8e690e Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Thu, 24 Dec 2020 00:08:07 +0100 Subject: [PATCH 1/7] fix typo in cmake file --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a87463d..58a63c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ find_program(CLANG_TIDY if(CLANG_TIDY) if(ENABLE_CLANG_TIDY) message(STATUS "set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY})") - set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_CMD} CACHE STRING "forced!" FORCE) + set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY} CACHE STRING "forced!" FORCE) else() set(CMAKE_CXX_CLANG_TIDY "" CACHE STRING "forced!" FORCE) # delete it endif() From 5910bd28176726fd358c2d739ecb2d294d26fb71 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Tue, 3 Aug 2021 23:50:04 +0200 Subject: [PATCH 2/7] add new sample to show problems with strcat --- CMakeLists.txt | 5 ++- GNUmakefile | 7 ++-- strcat.cpp | 110 +++++++++++++++++++++++++++++++++++++++++++++++++ to_string.cpp | 17 +++++++- 4 files changed, 133 insertions(+), 6 deletions(-) create mode 100644 strcat.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 58a63c2..1f8f0f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,8 +98,9 @@ find_package(Boost CONFIG) if(TARGET Boost::headers AND TARGET fmt::fmt) - add_executable(to_string to_string.cpp) - target_link_libraries(to_string fmt::fmt Boost::headers) + #FIXME! CK + #XXX add_executable(to_string to_string.cpp) + #XXX target_link_libraries(to_string fmt::fmt Boost::headers) endif() diff --git a/GNUmakefile b/GNUmakefile index 8c23ca7..4afaa08 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -25,7 +25,7 @@ CPPFLAGS?=-isystem /usr/local/include CC:=clang CFLAGS:=-std=c11 -Wextra -Wpedantic -Wshadow -#XXX CXX:=g++-10 +#XXX CXX:=g++-11 CXX:=clang++ CXXFLAGS:=-std=c++17 -Wextra -Wpedantic -Wshadow @@ -49,7 +49,7 @@ endif # -# from https://wiki.sei.cmu.edu/confluence/display/cplusplus/Clang +#XXX # from https://wiki.sei.cmu.edu/confluence/display/cplusplus/Clang # #XXX CXXFLAGS+=-analyzer-checker=cplusplus # EXP51-CPP. Do not delete an array through a pointer of the incorrect type @@ -89,7 +89,8 @@ export CC .PHONY: init all build check test format clean distclean TESTS:=$(wildcard cert-*.cpp) -#XXX TESTS+=cereal-test.cpp dynamic_pointer_cast.cpp safeComparison.cpp slice.cpp slide.cpp timeConversion.cpp to_string.cpp +#XXX TESTS+= strcat.cpp +#XXX TESTS+= cereal-test.cpp dynamic_pointer_cast.cpp safeComparison.cpp slice.cpp slide.cpp timeConversion.cpp to_string.cpp PROGRAMS:=$(TESTS:%.cpp=%) ###################################### diff --git a/strcat.cpp b/strcat.cpp new file mode 100644 index 0000000..0ac3334 --- /dev/null +++ b/strcat.cpp @@ -0,0 +1,110 @@ +// Abstract +// +// The standard C library includes functions that are designed to prevent +// buffer overflows, particularly strncpy() and strncat(). These +// universally available functions discard data larger than the specified +// length, regardless of whether it fits into the buffer. These functions +// are deprecated for new Windows code because they are frequently used +// incorrectly. +// +// see too +// https://us-cert.cisa.gov/bsi/articles/knowledge/coding-practices/strncpy-and-strncat +// https://us-cert.cisa.gov/bsi/articles/knowledge/coding-practices/strlcpy-and-strlcat +// and +// https://us-cert.cisa.gov/bsi/articles/knowledge/coding-practices/strcpy_s-and-strcat_s +// +#include +#include +#include + +constexpr size_t MAXPATHLEN{256}; +constexpr size_t MAX_STRING_LEN{50}; +constexpr const char* source = {"A not too long sentence here! "}; +constexpr const char* more = {"Too mutch ... text!!!!!"}; +const char *dir = "/usr/local/etc/snmp/"; +const char *file = "snmpd.conf"; + +namespace { + +#if !defined __APPLE__ && !defined __BSD__ +// If the return value is >= dstsize, the output string has been +// truncated. It is the caller's responsibility to handle this +size_t strlcpy(char* dst, const char* src, size_t len) +{ + int n = snprintf(dst, len, "%s", src); + assert(n >= 0 && (size_t)n < len); + + return n; +} +#endif + +void good_sample() +{ + char pname[MAXPATHLEN]; + size_t capacity = sizeof(pname); + + // ... + + size_t n = strlcpy(pname, dir, capacity); + if (n >= capacity) + { + goto toolong; + } + + capacity = sizeof(pname) - n ; + if (strlcpy(pname + n, file, capacity ) >= capacity) + { + goto toolong; + } + + std::cout << pname << std::endl; + return; + +toolong: + std::cerr << "truncated pname!" << std::endl; + exit(EXIT_FAILURE); +} + +} // namespace local + +int main() +{ + good_sample(); + + char dest[MAX_STRING_LEN + 1]; + +#undef USE_STRNCPY +#ifndef USE_STRNCPY + strlcpy(dest, source, MAX_STRING_LEN); +#else + // The strncpy() function doesn't null terminate the destination + // string if the source string is at least as long as the + // destination. (This behavior is defined by the C99 specification.) + // As a result, the destination string MUST be null terminated after + // calling strncpy(). + strncpy(dest, source, MAX_STRING_LEN); + dest[MAX_STRING_LEN] = '\0'; // NOTE: to be sure! CK + + // There's also a performance problem with strncpy() in that it fills + // the entire destination buffer with null bytes after the source + // data has been exhausted! +#endif + + std::cout << dest << std::endl; + +#undef SHOW_THE_BUG +#ifdef SHOW_THE_BUG + strncat(dest, source, MAX_STRING_LEN); // FIXME: buffer overflow! + std::cout << dest << std::endl; + dest[MAX_STRING_LEN] = '\0'; +#endif + + // The problem is that the last argument to strncat() should NOT be + // the total buffer length! It should be the space remaining after + // the call to strncpy(). Both functions require that you specify the + // remaining space and not the total size of the buffer. + strncat(dest, more, sizeof(dest) - strlen(dest) - 1); + + assert(strlen(dest) == MAX_STRING_LEN); + std::cout << dest << std::endl; +} diff --git a/to_string.cpp b/to_string.cpp index f110b6f..49ec40a 100644 --- a/to_string.cpp +++ b/to_string.cpp @@ -3,9 +3,11 @@ #if __cpp_lib_format # include // c++20 only using std::format; +using std::print; #else # include using ::fmt::format; +using ::fmt::print; #endif #include @@ -13,6 +15,17 @@ using ::fmt::format; #include #include +void foo() +{ + bool b = true; + //TODO std::string s(std::to_string(b)); // OK + uint8_t v = b ? 1 : 0; + std::string s = boost::lexical_cast(static_cast(v)); // OK + //XXX int i = std::stoi(""); // NOTE: std::invalid_argument: stoi: no conversion + int i = std::stoi(s); + print("The value {} was converted to {}\n", v, i); +} + int main() { double maxDouble = std::numeric_limits::max(); @@ -27,8 +40,10 @@ int main() double back_cast = boost::lexical_cast(str); std::cout << "boost::lexical_cast(" << back_cast << ") == " << back_stod << std::endl; - std::string s = format("The format::answer is {}.", maxDouble); + std::string s = format("The format::answer is {}", maxDouble); std::cout << s << std::endl; + foo(); + return 0; } From 3e784379af3f7e5ffd4135cf2894170e2a1a08a9 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Wed, 4 Aug 2021 10:14:21 +0200 Subject: [PATCH 3/7] add more strcat samples --- .gitignore | 4 +++- GNUmakefile | 2 +- strcat.cpp | 2 +- strcat_s.cpp | 36 ++++++++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 strcat_s.cpp diff --git a/.gitignore b/.gitignore index f54af81..fc748c9 100644 --- a/.gitignore +++ b/.gitignore @@ -32,9 +32,11 @@ cert-STR52 cert-STR53 compile_commands.json dynamic_pointer_cast +lookAndSay safeComparison slice slide +strcat +strcat_s timeConversion to_string -lookAndSay diff --git a/GNUmakefile b/GNUmakefile index 4afaa08..42f9013 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -27,7 +27,7 @@ CFLAGS:=-std=c11 -Wextra -Wpedantic -Wshadow #XXX CXX:=g++-11 CXX:=clang++ -CXXFLAGS:=-std=c++17 -Wextra -Wpedantic -Wshadow +CXXFLAGS:=-std=c++20 -Wextra -Wpedantic -Wshadow -Warray-bounds LDLIBS:=$(CURDIR)/library.a LDFLAGS:=-L/usr/local/lib diff --git a/strcat.cpp b/strcat.cpp index 0ac3334..9aff1d3 100644 --- a/strcat.cpp +++ b/strcat.cpp @@ -26,7 +26,7 @@ const char *file = "snmpd.conf"; namespace { -#if !defined __APPLE__ && !defined __BSD__ +#if !(defined(__APPLE__) || defined(__BSD__)) // If the return value is >= dstsize, the output string has been // truncated. It is the caller's responsibility to handle this size_t strlcpy(char* dst, const char* src, size_t len) diff --git a/strcat_s.cpp b/strcat_s.cpp new file mode 100644 index 0000000..55272a1 --- /dev/null +++ b/strcat_s.cpp @@ -0,0 +1,36 @@ +#define __STDC_WANT_LIB_EXT1__ 1 +#include +#include +#include + +int main(void) +{ + char dest[27] = "Hello "; + char src[] = "World!"; + constexpr size_t capacity = sizeof(dest); + +#if defined(__APPLE__) || defined(__BSD__) + size_t actual_len = strlcat(dest, src, capacity); + actual_len = strlcat(dest, " ..............", capacity); + if (actual_len >= capacity) { + puts("Warning: truncated string!"); + } else { + strlcat(dest, " Goodbye World!", capacity); + } + puts(dest); +#endif + +#if defined(__STDC_LIB_EXT1__) || defined(_WIN32) + set_constraint_handler_s(ignore_handler_s); + + int r = strcpy_s(dst, capacity, src); + printf("dst = \"%s\", r = %d\n", dst, r); + r = strcpy_s(dst, capacity, "Take even more tests."); + printf("dst = \"%s\", r = %d\n", dst, r); + + int err = strcat_s(dest, capacity, " .............. "); + printf("dest = \"%s\", err = %d\n", dest, err); + err = strcat_s(dest, capacity, " and this is too much"); + printf("dest = \"%s\", err = %d\n", dest, err); +#endif +} From d7c874a27e582fb8288043f9f8c2daf136d06d2f Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Wed, 4 Aug 2021 15:47:33 +0200 Subject: [PATCH 4/7] tested under debian stable --- CMakeLists.txt | 4 ++-- GNUmakefile | 4 ++-- strcat_s.cpp | 60 +++++++++++++++++++++++++++++++++++++++----------- 3 files changed, 51 insertions(+), 17 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1f8f0f0..0162f8b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,8 @@ -cmake_minimum_required(VERSION 3.15...3.19) +cmake_minimum_required(VERSION 3.14...3.21) option(CMAKE_EXPORT_COMPILE_COMMANDS "create compile_commands.json" ON) -project(cert-test LANGUAGES CXX VERSION 0.1.8) +project(cert-test LANGUAGES CXX VERSION 0.1.9) #---------------------------------------------------------- # Compiler config diff --git a/GNUmakefile b/GNUmakefile index 42f9013..be635a5 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -21,13 +21,13 @@ GENERATOR?=-G Ninja TARGET_ARCH:= CPPFLAGS?=-isystem /usr/local/include -#XXX CC:=gcc-10 +#XXX CC:=gcc-11 CC:=clang CFLAGS:=-std=c11 -Wextra -Wpedantic -Wshadow #XXX CXX:=g++-11 CXX:=clang++ -CXXFLAGS:=-std=c++20 -Wextra -Wpedantic -Wshadow -Warray-bounds +CXXFLAGS:=-std=c++17 -Wextra -Wpedantic -Wshadow -Warray-bounds LDLIBS:=$(CURDIR)/library.a LDFLAGS:=-L/usr/local/lib diff --git a/strcat_s.cpp b/strcat_s.cpp index 55272a1..69456ed 100644 --- a/strcat_s.cpp +++ b/strcat_s.cpp @@ -2,22 +2,56 @@ #include #include #include +#include + +namespace { + +#if !(defined(__APPLE__) || defined(__BSD__)) +// If the return value is >= dstsize, the output string has been +// truncated. It is the caller's responsibility to handle this +size_t strlcpy(char* dst, const char* src, size_t capacity) +{ + int len = snprintf(dst, capacity, "%s", src); + printf("dst = \"%s\", len = %d, capacity = %zu\n", dst, len, capacity); + + if(len >= 0 && (size_t)len >= capacity) { + puts("Warning: truncated str at strlcpy()!"); + } + + return len; +} + +size_t strlcat(char* dst, const char* src, size_t capacity) +{ + size_t actual_used = strlen(dst); + if (capacity > (actual_used + 1)) { + return strlcpy(dst + actual_used, src, capacity - actual_used); + } + + return actual_used; +} +#endif +} int main(void) { - char dest[27] = "Hello "; - char src[] = "World!"; - constexpr size_t capacity = sizeof(dest); + char dst[15 + 2 * 6 + 1] = "Hello "; + char src[6 + 1] = "World!"; + constexpr size_t capacity = sizeof(dst); -#if defined(__APPLE__) || defined(__BSD__) - size_t actual_len = strlcat(dest, src, capacity); - actual_len = strlcat(dest, " ..............", capacity); +#if 1 // defined(__APPLE__) || defined(__BSD__) + size_t actual_len = strlcat(dst, src, capacity); + actual_len = strlcat(dst, " .............#", capacity); if (actual_len >= capacity) { puts("Warning: truncated string!"); - } else { - strlcat(dest, " Goodbye World!", capacity); } - puts(dest); + //XXX else + { + actual_len = strlcat(dst, " Goodbye World!", capacity); + printf("dst = \"%s\", len = %zu, capacity = %zu\n", dst, actual_len, capacity); + assert(actual_len < capacity); + } + //XXX puts(dst); #endif #if defined(__STDC_LIB_EXT1__) || defined(_WIN32) @@ -28,9 +62,9 @@ int main(void) r = strcpy_s(dst, capacity, "Take even more tests."); printf("dst = \"%s\", r = %d\n", dst, r); - int err = strcat_s(dest, capacity, " .............. "); - printf("dest = \"%s\", err = %d\n", dest, err); - err = strcat_s(dest, capacity, " and this is too much"); - printf("dest = \"%s\", err = %d\n", dest, err); + int err = strcat_s(dst, capacity, " .............. "); + printf("dst = \"%s\", err = %d\n", dst, err); + err = strcat_s(dst, capacity, " and this is too much"); + printf("dst = \"%s\", err = %d\n", dst, err); #endif } From 5e78b0f9e402c56fc8f67d40f45ead7047e3eb21 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Wed, 4 Aug 2021 16:26:37 +0200 Subject: [PATCH 5/7] fix strlcat according to the BSD manual --- strcat_s.cpp | 44 +++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 17 deletions(-) diff --git a/strcat_s.cpp b/strcat_s.cpp index 69456ed..087e6b1 100644 --- a/strcat_s.cpp +++ b/strcat_s.cpp @@ -1,58 +1,68 @@ #define __STDC_WANT_LIB_EXT1__ 1 +#include #include #include #include -#include namespace { #if !(defined(__APPLE__) || defined(__BSD__)) -// If the return value is >= dstsize, the output string has been -// truncated. It is the caller's responsibility to handle this +// Like snprintf(3), the strlcpy() and strlcat() functions return the +// total length of the string they tried to create. size_t strlcpy(char* dst, const char* src, size_t capacity) { + assert(dst != nullptr); int len = snprintf(dst, capacity, "%s", src); printf("dst = \"%s\", len = %d, capacity = %zu\n", dst, len, capacity); - if(len >= 0 && (size_t)len >= capacity) { + if (len >= 0 && (size_t)len >= capacity) { puts("Warning: truncated str at strlcpy()!"); } return len; } +// If the return value is >= dstsize, the output string has been +// truncated. It is the caller's responsibility to handle this size_t strlcat(char* dst, const char* src, size_t capacity) { + assert(dst != nullptr); size_t actual_used = strlen(dst); + assert(actual_used < capacity); + if (capacity > (actual_used + 1)) { return strlcpy(dst + actual_used, src, capacity - actual_used); } - return actual_used; + return actual_used + strlen(src); // NOTE: total_len } #endif -} + +} // namespace int main(void) { char dst[15 + 2 * 6 + 1] = "Hello "; char src[6 + 1] = "World!"; - constexpr size_t capacity = sizeof(dst); + constexpr size_t capacity = sizeof(dst); // NOTE: 28 -#if 1 // defined(__APPLE__) || defined(__BSD__) - size_t actual_len = strlcat(dst, src, capacity); - actual_len = strlcat(dst, " .............#", capacity); - if (actual_len >= capacity) { + size_t total_len = strlcat(dst, src, capacity); + total_len = strlcat(dst, " .............#", capacity); + printf("dst = \"%s\", len = %zu, capacity = %zu\n", dst, total_len, capacity); + if (total_len >= capacity) { puts("Warning: truncated string!"); } - //XXX else + // XXX else { - actual_len = strlcat(dst, " Goodbye World!", capacity); - printf("dst = \"%s\", len = %zu, capacity = %zu\n", dst, actual_len, capacity); - assert(actual_len < capacity); + total_len = strlcat(dst, " Goodbye World!", capacity); + printf("dst = \"%s\", len = %zu, capacity = %zu\n", dst, total_len, capacity); + assert(total_len == 42); } - //XXX puts(dst); -#endif + // XXX puts(dst); + + total_len = strlcpy(dst, "Hello World! .............#1234567890", capacity); + printf("dst = \"%s\", len = %zu, capacity = %zu\n", dst, total_len, capacity); + assert(total_len == 37); #if defined(__STDC_LIB_EXT1__) || defined(_WIN32) set_constraint_handler_s(ignore_handler_s); From 269e112e3ff805e016d72d4e6ecf36b9d63f7052 Mon Sep 17 00:00:00 2001 From: Claus Klein Date: Wed, 4 Aug 2021 16:36:41 +0200 Subject: [PATCH 6/7] add_test(strlcat_s) too --- CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0162f8b..dfc92c9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -115,6 +115,10 @@ target_compile_features(dynamic_pointer_cast PRIVATE cxx_std_17) add_executable(slice slice.cpp) target_compile_features(slice PRIVATE cxx_std_17) +add_executable(strcat_s strcat_s.cpp) +target_compile_features(strcat_s PRIVATE cxx_std_17) +add_test(NAME strcat_s COMMAND strcat_s) + add_executable(lookAndSay lookAndSay.cpp) target_compile_features(lookAndSay PRIVATE cxx_std_17) From cb5199465a4561cf6ef17f30cd98ec04c90d4481 Mon Sep 17 00:00:00 2001 From: ClausKlein Date: Tue, 8 Oct 2024 09:04:43 +0200 Subject: [PATCH 7/7] Add CMakePreset --- CMakeLists.txt | 14 ++++--- CMakePresets.json | 82 ++++++++++++++++++++++++++++++++++++++ GNUmakefile | 8 ++-- cert-CTR58.cpp | 2 +- strcat_s.cpp => strcat_s.c | 13 +++--- 5 files changed, 101 insertions(+), 18 deletions(-) create mode 100644 CMakePresets.json rename strcat_s.cpp => strcat_s.c (93%) diff --git a/CMakeLists.txt b/CMakeLists.txt index dfc92c9..80cfff2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,14 +1,14 @@ -cmake_minimum_required(VERSION 3.14...3.21) +cmake_minimum_required(VERSION 3.14...3.30) option(CMAKE_EXPORT_COMPILE_COMMANDS "create compile_commands.json" ON) -project(cert-test LANGUAGES CXX VERSION 0.1.9) +project(cert-test LANGUAGES CXX C VERSION 0.1.9) #---------------------------------------------------------- # Compiler config #---------------------------------------------------------- if(NOT DEFINED CMAKE_CXX_STANDARD) - set(CMAKE_CXX_STANDARD 17) + set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) endif() @@ -34,6 +34,10 @@ if(CLANG_TIDY) endif() endif() +add_library(rary STATIC library.cpp library.h) +target_include_directories(rary PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) +target_compile_features(rary PRIVATE cxx_std_98) + #---------------------------------------------------------- enable_testing() #---------------------------------------------------------- @@ -47,7 +51,7 @@ foreach(TEST_SOURCE ${TESTS}) add_executable(${TEST_TARGET} ${TEST_SOURCE}) target_compile_features(${TEST_TARGET} PRIVATE cxx_std_17) - target_link_libraries(${TEST_TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/library.a) + target_link_libraries(${TEST_TARGET} PRIVATE rary) add_test(NAME "${TEST_TARGET}" COMMAND "${TEST_TARGET}") endforeach() @@ -115,7 +119,7 @@ target_compile_features(dynamic_pointer_cast PRIVATE cxx_std_17) add_executable(slice slice.cpp) target_compile_features(slice PRIVATE cxx_std_17) -add_executable(strcat_s strcat_s.cpp) +add_executable(strcat_s strcat_s.c) target_compile_features(strcat_s PRIVATE cxx_std_17) add_test(NAME strcat_s COMMAND strcat_s) diff --git a/CMakePresets.json b/CMakePresets.json new file mode 100644 index 0000000..c6a4af3 --- /dev/null +++ b/CMakePresets.json @@ -0,0 +1,82 @@ +{ + "version": 9, + "configurePresets": [ + { + "name": "default", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build", + "hidden": true, + "cacheVariables": { + "CMAKE_BUILD_TYPE": "${presetName}" + }, + "environment": { + "PRESET_NAME": "${presetName}" + } + }, + { + "name": "Debug", + "inherits": "default" + }, + { + "name": "Release", + "inherits": "default" + } + ], + "buildPresets": [ + { + "name": "Debug", + "configurePreset": "Debug" + }, + { + "name": "Release", + "configurePreset": "Release" + } + ], + "testPresets": [ + { + "name": "Debug", + "configurePreset": "Debug" + }, + { + "name": "Release", + "configurePreset": "Release" + } + + ], + "workflowPresets": [ + { + "name": "Debug", + "steps": [ + { + "type": "configure", + "name": "Debug" + }, + { + "type": "build", + "name": "Debug" + }, + { + "type": "test", + "name": "Debug" + } + ] + }, + { + "name": "Release", + "steps": [ + { + "type": "configure", + "name": "Release" + }, + { + "type": "build", + "name": "Release" + }, + { + "type": "test", + "name": "Release" + } + ] + } + ] +} diff --git a/GNUmakefile b/GNUmakefile index be635a5..4e039c0 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -21,11 +21,11 @@ GENERATOR?=-G Ninja TARGET_ARCH:= CPPFLAGS?=-isystem /usr/local/include -#XXX CC:=gcc-11 +#XXX CC:=gcc-14 CC:=clang -CFLAGS:=-std=c11 -Wextra -Wpedantic -Wshadow +CFLAGS:=-std=c17 -Wextra -Wpedantic -Wshadow -#XXX CXX:=g++-11 +#XXX CXX:=g++-14 CXX:=clang++ CXXFLAGS:=-std=c++17 -Wextra -Wpedantic -Wshadow -Warray-bounds @@ -41,7 +41,7 @@ BUILDDIR?=$(CURDIR)/build UNAME:=$(shell uname) ifeq ($(UNAME),Darwin) SCAN_BUILD?=/usr/local/opt/llvm/bin/scan-build - #XXX CPPFLAGS+=-isystem /usr/local/Cellar/llvm/11.0.0/include/c++/v1/ + #XXX CPPFLAGS+=-isystem /usr/local/Cellar/llvm/19.1.0/include/c++/v1/ else CLANG_VERSION:=$(shell clang --version | grep -w version | perl -n -e 'print if s/^.*clang version (\d+)\..*/$$1/') SCAN_BUILD:=$(shell which scan-build-$(CLANG_VERSION) || which scan-build) diff --git a/cert-CTR58.cpp b/cert-CTR58.cpp index 130ab6a..c9aa059 100644 --- a/cert-CTR58.cpp +++ b/cert-CTR58.cpp @@ -10,7 +10,7 @@ namespace { -class MutablePredicate : public std::unary_function +class MutablePredicate : public std::__unary_function { size_t timesCalled; diff --git a/strcat_s.cpp b/strcat_s.c similarity index 93% rename from strcat_s.cpp rename to strcat_s.c index 087e6b1..08cff6e 100644 --- a/strcat_s.cpp +++ b/strcat_s.c @@ -1,10 +1,9 @@ #define __STDC_WANT_LIB_EXT1__ 1 -#include -#include -#include -#include +#include +#include +#include +#include -namespace { #if !(defined(__APPLE__) || defined(__BSD__)) // Like snprintf(3), the strlcpy() and strlcat() functions return the @@ -38,13 +37,11 @@ size_t strlcat(char* dst, const char* src, size_t capacity) } #endif -} // namespace - int main(void) { char dst[15 + 2 * 6 + 1] = "Hello "; char src[6 + 1] = "World!"; - constexpr size_t capacity = sizeof(dst); // NOTE: 28 + const size_t capacity = sizeof(dst); // NOTE: 28 size_t total_len = strlcat(dst, src, capacity); total_len = strlcat(dst, " .............#", capacity);