diff --git a/.github/workflows/autopr.yaml b/.github/workflows/autopr.yaml index ba498eb..8459003 100644 --- a/.github/workflows/autopr.yaml +++ b/.github/workflows/autopr.yaml @@ -14,7 +14,7 @@ jobs: pull-requests: write steps: - name: Create PR - uses: actions/github-script@v7 + uses: actions/github-script@v8 with: script: | const { repo, owner } = context.repo; diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index 87c01e7..d99de6d 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -10,8 +10,8 @@ on: env: NODE_VERSION: 22 - PYTHON_VERSION: 3.x - JAVA_VERSION: 17 + PYTHON_VERSION: 3.13 + JAVA_VERSION: 21 permissions: contents: read diff --git a/VERSION b/VERSION index da2b974..aa5654a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -1.6.57 +1.6.58 diff --git a/c/CMakeLists.txt b/c/CMakeLists.txt index c3e26e4..9a1a682 100644 --- a/c/CMakeLists.txt +++ b/c/CMakeLists.txt @@ -26,7 +26,7 @@ option(BUILD_SHARED_LIB "Build a shared library" ON) if(CMAKE_COMPILER_IS_GNUCC) message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") execute_process(COMMAND ${CMAKE_C_COMPILER} -dumpversion OUTPUT_VARIABLE GCC_VERSION) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D VERSION='\"${PROJECT_VERSION}\"' -s -pedantic -std=c17 -Wall -Wextra -Wno-strict-prototypes -Wcast-align -Wundef -Wformat -Wformat-security") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -D VERSION='\"${PROJECT_VERSION}\"' -s -pedantic -std=c2x -Wall -Wextra -Wno-strict-prototypes -Wcast-align -Wundef -Wformat -Wformat-security") if (GCC_VERSION VERSION_GREATER 4.8 OR GCC_VERSION VERSION_EQUAL 4.8) set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wshadow") diff --git a/c/Makefile b/c/Makefile index 9b62de0..99b9c4c 100644 --- a/c/Makefile +++ b/c/Makefile @@ -195,7 +195,7 @@ endif # Test C code compatibility with C++ .PHONY: testcpp testcpp: - find ./src/numkey -type f -name '*.h' -exec gcc -c -pedantic -Werror -Wall -Wextra -Wcast-align -Wundef -Wformat -Wformat-security -std=c++17 -x c++ -o /dev/null {} \; + find ./src/numkey -type f -name '*.h' -exec gcc -c -pedantic -Werror -Wall -Wextra -Wcast-align -Wundef -Wformat -Wformat-security -std=c++23 -x c++ -o /dev/null {} \; # use clang-tidy .PHONY: tidy diff --git a/c/doc/Doxyfile b/c/doc/Doxyfile index 87eec83..be27ee0 100644 --- a/c/doc/Doxyfile +++ b/c/doc/Doxyfile @@ -32,7 +32,7 @@ PROJECT_NAME = "NumKey" # This could be handy for archiving the generated documentation or # if some version control system is used. -PROJECT_NUMBER = 1.6.57 +PROJECT_NUMBER = 1.6.58 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer diff --git a/c/nk/nk.c b/c/nk/nk.c index a7cc233..eab9d9e 100644 --- a/c/nk/nk.c +++ b/c/nk/nk.c @@ -10,8 +10,8 @@ #include +#include #include -#include #include #include "../src/numkey/numkey.h" diff --git a/c/src/numkey/binsearch.h b/c/src/numkey/binsearch.h index 79141da..c3095d0 100644 --- a/c/src/numkey/binsearch.h +++ b/c/src/numkey/binsearch.h @@ -6,7 +6,7 @@ // @author Nicola Asuni // @link https://github.com/tecnickcom/binsearch // @license MIT (see LICENSE file) -// @copyright (c) 2017-2024 Nicola Asuni - Tecnick.com +// @copyright (c) 2017-2025 Nicola Asuni - Tecnick.com /** * @file binsearch.h @@ -44,6 +44,7 @@ #include #include #include +#include #include #include #include @@ -989,7 +990,8 @@ static inline void mmap_binfile(const char *file, mmfile_t *mf) mf->dlength = 0; mf->nrows = 0; struct stat statbuf; - if (((mf->fd = open(file, O_RDONLY)) < 0) || (fstat(mf->fd, &statbuf) < 0)) + mf->fd = open(file, O_RDONLY); + if ((mf->fd < 0) || (fstat(mf->fd, &statbuf) < 0)) { return; } diff --git a/c/src/numkey/countrykey.h b/c/src/numkey/countrykey.h index 66b309e..6c82927 100644 --- a/c/src/numkey/countrykey.h +++ b/c/src/numkey/countrykey.h @@ -18,6 +18,7 @@ #define NUMKEY_COUNTRYKEY_H #include +#include #include /** diff --git a/c/src/numkey/hex.h b/c/src/numkey/hex.h index 9ec7639..596033b 100644 --- a/c/src/numkey/hex.h +++ b/c/src/numkey/hex.h @@ -1,5 +1,3 @@ -// NumKey -// // hex.h // // @category Libraries @@ -18,9 +16,12 @@ #define NUMKEY_HEX_H #include +#include #include /** @brief Returns uint64_t hexadecimal string (16 characters). + * + * * * @param n Number to parse * @param str String buffer to be returned (it must be sized 17 bytes at least). @@ -36,6 +37,9 @@ static inline size_t hex_uint64_t(uint64_t n, char *str) } /** @brief Parses a 16 chars hexadecimal string and returns the code. + * + * This function parses a hexadecimal string and returns the corresponding + * unsigned integer number. * * @param s Hexadecimal string to parse (it must contain 16 hexadecimal characters). * @@ -69,4 +73,4 @@ static inline uint64_t parse_hex_uint64_t(const char *s) return v; } -#endif // NUMKEY_HEX_H \ No newline at end of file +#endif // NUMKEY_HEX_H diff --git a/c/src/numkey/numkey.h b/c/src/numkey/numkey.h index c06bebd..d9861c7 100644 --- a/c/src/numkey/numkey.h +++ b/c/src/numkey/numkey.h @@ -20,6 +20,7 @@ #define NUMKEY_NUMKEY_H #include +#include #include #include "hex.h" diff --git a/c/src/numkey/prefixkey.h b/c/src/numkey/prefixkey.h index e40b6cc..22afc3f 100644 --- a/c/src/numkey/prefixkey.h +++ b/c/src/numkey/prefixkey.h @@ -18,6 +18,7 @@ #define NUMKEY_PREFIXKEY_H #include +#include #include #define PKNUMMAXLEN 15 //!< Maximum number of digits to store for the prefixkey. diff --git a/c/src/numkey/set.h b/c/src/numkey/set.h index e569c32..c446698 100644 --- a/c/src/numkey/set.h +++ b/c/src/numkey/set.h @@ -1,5 +1,3 @@ -// NumKey -// // set.h // // @category Libraries @@ -18,7 +16,7 @@ #define NUMKEY_SET_H #include -#include +#include #define RADIX_SORT_COUNT_BLOCK \ uint32_t c7[256]= {0}, c6[256]= {0}, c5[256]= {0}, c4[256]= {0}, c3[256]= {0}, c2[256]= {0}, c1[256]= {0}, c0[256]= {0}; \ @@ -137,8 +135,13 @@ static inline void reverse_uint64_t(uint64_t *arr, uint64_t nitems) { uint64_t *last = (arr + nitems); uint64_t tmp = 0; - while ((arr != last) && (arr != --last)) + while (arr != last) { + --last; + if (arr == last) + { + break; + } tmp = *last; *last = *arr; *arr++ = tmp; @@ -163,9 +166,12 @@ static inline uint64_t *unique_uint64_t(uint64_t *arr, uint64_t nitems) uint64_t *p = arr; while (++arr != last) { - if ((*p != *arr) && (*p++ != *arr)) + if (*p != *arr) { - *p = *arr; + if (*p++ != *arr) + { + *p = *arr; + } } } return ++p; @@ -243,4 +249,4 @@ static inline uint64_t *union_uint64_t(uint64_t *a_arr, uint64_t a_nitems, uint6 return o_arr; } -#endif // NUMKEY_SET_H \ No newline at end of file +#endif // NUMKEY_SET_H diff --git a/c/test/test_binsearch.c b/c/test/test_binsearch.c index 64e1264..4eecaba 100644 --- a/c/test/test_binsearch.c +++ b/c/test/test_binsearch.c @@ -1,6 +1,24 @@ -// Nicola Asuni +// BinSearch +// +// test_binsearch.h +// +// @category Test +// @author Nicola Asuni +// @link https://github.com/tecnickcom/binsearch +// @license MIT (see LICENSE file) +// @copyright (c) 2017-2025 Nicola Asuni - Tecnick.com + +#ifdef __STDC__LIB_EXT1__ +#define __STDC_WANT_LIB_EXT1__ 1 +#else +// Ignore clang-tidy warning for deprecated or unsafe buffer handling +// NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling) +#define fprintf_s fprintf +#endif #include +#include +#include #include #include #include @@ -21,7 +39,7 @@ typedef struct t_test_uint8_t uint64_t foundLast; uint64_t foundLFirst; uint64_t foundLLast; -} __attribute__((packed)) __attribute__((aligned(128))) t_test_uint8_t; +} __attribute__((packed, aligned(128))) t_test_uint8_t; // bytes=1, bitstart=0, bitend=7, bitmask=00000000000000ff, rshift=0 @@ -206,7 +224,7 @@ typedef struct t_test_uint16_t uint64_t foundLast; uint64_t foundLFirst; uint64_t foundLLast; -} __attribute__((packed)) __attribute__((aligned(128))) t_test_uint16_t; +} __attribute__((packed, aligned(128))) t_test_uint16_t; // bytes=2, bitstart=0, bitend=15, bitmask=000000000000ffff, rshift=0 @@ -391,7 +409,7 @@ typedef struct t_test_uint32_t uint64_t foundLast; uint64_t foundLFirst; uint64_t foundLLast; -} __attribute__((packed)) __attribute__((aligned(128))) t_test_uint32_t; +} __attribute__((packed, aligned(128))) t_test_uint32_t; // bytes=4, bitstart=8, bitend=23, bitmask=0000000000ffffff, rshift=8 @@ -575,7 +593,7 @@ typedef struct t_test_uint64_t uint64_t foundLast; uint64_t foundLFirst; uint64_t foundLLast; -} __attribute__((packed)) __attribute__((aligned(128))) t_test_uint64_t; +} __attribute__((packed, aligned(128))) t_test_uint64_t; // bytes=8, bitstart=16, bitend=47, bitmask=0000ffffffffffff, rshift=16 @@ -760,7 +778,7 @@ int test_bytes_to_##O##_##T(mmfile_t mf, uint64_t blklen) \ h = bytes_##O##_to_##T(mf.src, get_address(blklen, test_data_##O##_##T[i].blkpos, test_data_##O##_##T[i].foundFirst)); \ if (h != test_data_##O##_##T[i].search) \ { \ - (void) fprintf(stderr, "%s (%d) Expected %" PRIx64 ", got %" PRIx64 "\n", __func__, i, (uint64_t)test_data_##O##_##T[i].search, (uint64_t)h); \ + (void)fprintf_s(stderr, "%s (%d) Expected %" PRIx64 ", got %" PRIx64 "\n", __func__, i, (uint64_t)test_data_##O##_##T[i].search, (uint64_t)h); \ ++errors; \ } \ } \ @@ -793,17 +811,17 @@ int test_find_first_##O##_##T(mmfile_t mf, uint64_t blklen) \ ffound = find_first_##O##_##T(mf.src, blklen, test_data_##O##_##T[i].blkpos, &first, &last, test_data_##O##_##T[i].search); \ if (ffound != test_data_##O##_##T[i].foundFirst) \ { \ - (void) fprintf(stderr, "%s (%d) Expected found %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_##O##_##T[i].foundFirst, ffound); \ + (void)fprintf_s(stderr, "%s (%d) Expected found %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_##O##_##T[i].foundFirst, ffound); \ ++errors; \ } \ if (first != test_data_##O##_##T[i].foundFFirst) \ { \ - (void) fprintf(stderr, "%s (%d) Expected first %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_##O##_##T[i].foundFFirst, first); \ + (void)fprintf_s(stderr, "%s (%d) Expected first %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_##O##_##T[i].foundFFirst, first); \ ++errors; \ } \ if (last != test_data_##O##_##T[i].foundFLast) \ { \ - (void) fprintf(stderr, "%s (%d) Expected last %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_##O##_##T[i].foundFLast, last); \ + (void)fprintf_s(stderr, "%s (%d) Expected last %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_##O##_##T[i].foundFLast, last); \ ++errors; \ } \ numitems = (test_data_##O##_##T[i].foundLast - test_data_##O##_##T[i].foundFirst); \ @@ -817,7 +835,7 @@ int test_find_first_##O##_##T(mmfile_t mf, uint64_t blklen) \ } \ if (counter != numitems) \ { \ - (void) fprintf(stderr, "%s HAS_NEXT (%d) Expected %" PRIu64 ", got %" PRIu64 "\n", __func__, i, numitems, counter); \ + (void)fprintf_s(stderr, "%s HAS_NEXT (%d) Expected %" PRIu64 ", got %" PRIu64 "\n", __func__, i, numitems, counter); \ ++errors; \ } \ } \ @@ -826,17 +844,17 @@ int test_find_first_##O##_##T(mmfile_t mf, uint64_t blklen) \ lfound = find_first_sub_##O##_##T(mf.src, blklen, test_data_sub_##O##_##T[i].blkpos, bitstart, bitend, &first, &last, test_data_sub_##O##_##T[i].search); \ if (lfound != test_data_sub_##O##_##T[i].foundFirst) \ { \ - (void) fprintf(stderr, "%s SUB (%d) Expected found %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_sub_##O##_##T[i].foundFirst, lfound); \ + (void)fprintf_s(stderr, "%s SUB (%d) Expected found %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_sub_##O##_##T[i].foundFirst, lfound); \ ++errors; \ } \ if (first != test_data_sub_##O##_##T[i].foundFFirst) \ { \ - (void) fprintf(stderr, "%s SUB (%d) Expected first %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_sub_##O##_##T[i].foundFFirst, first); \ + (void)fprintf_s(stderr, "%s SUB (%d) Expected first %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_sub_##O##_##T[i].foundFFirst, first); \ ++errors; \ } \ if (last != test_data_sub_##O##_##T[i].foundFLast) \ { \ - (void) fprintf(stderr, "%s SUB (%d) Expected last %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_sub_##O##_##T[i].foundFLast, last); \ + (void)fprintf_s(stderr, "%s SUB (%d) Expected last %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_sub_##O##_##T[i].foundFLast, last); \ ++errors; \ } \ numitems = (test_data_sub_##O##_##T[i].foundLast - test_data_sub_##O##_##T[i].foundFirst); \ @@ -850,7 +868,7 @@ int test_find_first_##O##_##T(mmfile_t mf, uint64_t blklen) \ } \ if (counter != numitems) \ { \ - (void) fprintf(stderr, "%s HAS_NEXT_SUB (%d) Expected %" PRIu64 ", got %" PRIu64 "\n", __func__, i, numitems, counter); \ + (void)fprintf_s(stderr, "%s HAS_NEXT_SUB (%d) Expected %" PRIu64 ", got %" PRIu64 "\n", __func__, i, numitems, counter); \ ++errors; \ } \ } \ @@ -883,17 +901,17 @@ int test_find_last_##O##_##T(mmfile_t mf, uint64_t blklen) \ ffound = find_last_##O##_##T(mf.src, blklen, test_data_##O##_##T[i].blkpos, &first, &last, test_data_##O##_##T[i].search); \ if (ffound != test_data_##O##_##T[i].foundLast) \ { \ - (void) fprintf(stderr, "%s (%d) Expected found %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_##O##_##T[i].foundLast, ffound); \ + (void)fprintf_s(stderr, "%s (%d) Expected found %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_##O##_##T[i].foundLast, ffound); \ ++errors; \ } \ if (first != test_data_##O##_##T[i].foundLFirst) \ { \ - (void) fprintf(stderr, "%s (%d) Expected first %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_##O##_##T[i].foundLFirst, first); \ + (void)fprintf_s(stderr, "%s (%d) Expected first %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_##O##_##T[i].foundLFirst, first); \ ++errors; \ } \ if (last != test_data_##O##_##T[i].foundLLast) \ { \ - (void) fprintf(stderr, "%s (%d) Expected last %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_##O##_##T[i].foundLLast, last); \ + (void)fprintf_s(stderr, "%s (%d) Expected last %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_##O##_##T[i].foundLLast, last); \ ++errors; \ } \ numitems = (test_data_##O##_##T[i].foundLast - test_data_##O##_##T[i].foundFirst); \ @@ -907,7 +925,7 @@ int test_find_last_##O##_##T(mmfile_t mf, uint64_t blklen) \ } \ if (counter != numitems) \ { \ - (void) fprintf(stderr, "%s HAS_PREV (%d) Expected %" PRIu64 ", got %" PRIu64 "\n", __func__, i, numitems, counter); \ + (void)fprintf_s(stderr, "%s HAS_PREV (%d) Expected %" PRIu64 ", got %" PRIu64 "\n", __func__, i, numitems, counter); \ ++errors; \ } \ } \ @@ -916,17 +934,17 @@ int test_find_last_##O##_##T(mmfile_t mf, uint64_t blklen) \ lfound = find_last_sub_##O##_##T(mf.src, blklen, test_data_sub_##O##_##T[i].blkpos, bitstart, bitend, &first, &last, test_data_sub_##O##_##T[i].search); \ if (lfound != test_data_sub_##O##_##T[i].foundLast) \ { \ - (void) fprintf(stderr, "%s SUB (%d) Expected found %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_sub_##O##_##T[i].foundLast, lfound); \ + (void)fprintf_s(stderr, "%s SUB (%d) Expected found %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_sub_##O##_##T[i].foundLast, lfound); \ ++errors; \ } \ if (first != test_data_sub_##O##_##T[i].foundLFirst) \ { \ - (void) fprintf(stderr, "%s SUB (%d) Expected first %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_sub_##O##_##T[i].foundLFirst, first); \ + (void)fprintf_s(stderr, "%s SUB (%d) Expected first %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_sub_##O##_##T[i].foundLFirst, first); \ ++errors; \ } \ if (last != test_data_sub_##O##_##T[i].foundLLast) \ { \ - (void) fprintf(stderr, "%s SUB (%d) Expected last %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_sub_##O##_##T[i].foundLLast, last); \ + (void)fprintf_s(stderr, "%s SUB (%d) Expected last %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_data_sub_##O##_##T[i].foundLLast, last); \ ++errors; \ } \ numitems = (test_data_sub_##O##_##T[i].foundLast - test_data_sub_##O##_##T[i].foundFirst); \ @@ -940,7 +958,7 @@ int test_find_last_##O##_##T(mmfile_t mf, uint64_t blklen) \ } \ if (counter != numitems) \ { \ - (void) fprintf(stderr, "%s HAS_PREV_SUB (%d) Expected %" PRIu64 ", got %" PRIu64 "\n", __func__, i, numitems, counter); \ + (void)fprintf_s(stderr, "%s HAS_PREV_SUB (%d) Expected %" PRIu64 ", got %" PRIu64 "\n", __func__, i, numitems, counter); \ ++errors; \ } \ } \ @@ -961,7 +979,7 @@ define_test_find_last(le, uint64_t) uint64_t get_time() { struct timespec t; - (void) timespec_get(&t, TIME_UTC); + (void)timespec_get(&t, TIME_UTC); return (((uint64_t)t.tv_sec * 1000000000) + (uint64_t)t.tv_nsec); } @@ -982,7 +1000,7 @@ void benchmark_find_first_##O##_##T(mmfile_t mf, uint64_t blklen, uint64_t nrows found = find_first_##O##_##T(mf.src, blklen, test_data_##O##_##T[4].blkpos, &first, &last, test_data_##O##_##T[4].search); \ } \ tend = get_time(); \ - (void) fprintf(stdout, " * %s : %lu ns/op (%" PRIx64 ")\n", __func__, (tend - tstart)/(uint64_t)(size*4), found); \ + (void)fprintf_s(stdout, " * %s : %lu ns/op (%" PRIx64 ")\n", __func__, (tend - tstart)/(uint64_t)(size*4), found); \ } define_benchmark_find_first(be, uint8_t) @@ -1011,7 +1029,7 @@ void benchmark_find_last_##O##_##T(mmfile_t mf, uint64_t blklen, uint64_t nrows) found = find_last_##O##_##T(mf.src, blklen, test_data_##O##_##T[4].blkpos, &first, &last, test_data_##O##_##T[4].search); \ } \ tend = get_time(); \ - (void) fprintf(stdout, " * %s : %lu ns/op (%" PRIx64 ")\n", __func__, (tend - tstart)/(uint64_t)(size*4), found); \ + (void)fprintf_s(stdout, " * %s : %lu ns/op (%" PRIx64 ")\n", __func__, (tend - tstart)/(uint64_t)(size*4), found); \ } define_benchmark_find_last(be, uint8_t) @@ -1043,7 +1061,7 @@ void benchmark_find_first_sub_##O##_##T(mmfile_t mf, uint64_t blklen, uint64_t n found = find_first_sub_##O##_##T(mf.src, blklen, test_data_##O##_##T[4].blkpos, bitstart, bitend, &first, &last, test_data_##O##_##T[4].search); \ } \ tend = get_time(); \ - (void) fprintf(stdout, " * %s : %lu ns/op (%" PRIx64 ")\n", __func__, (tend - tstart)/(uint64_t)(size*4), found); \ + (void)fprintf_s(stdout, " * %s : %lu ns/op (%" PRIx64 ")\n", __func__, (tend - tstart)/(uint64_t)(size*4), found); \ } define_benchmark_find_first_sub(be, uint8_t) @@ -1075,7 +1093,7 @@ void benchmark_find_last_sub_##O##_##T(mmfile_t mf, uint64_t blklen, uint64_t nr found = find_last_sub_##O##_##T(mf.src, blklen, test_data_##O##_##T[4].blkpos, bitstart, bitend, &first, &last, test_data_##O##_##T[4].search); \ } \ tend = get_time(); \ - (void) fprintf(stdout, " * %s : %lu ns/op (%" PRIx64 ")\n", __func__, (tend - tstart)/(uint64_t)(size*4), found); \ + (void)fprintf_s(stdout, " * %s : %lu ns/op (%" PRIx64 ")\n", __func__, (tend - tstart)/(uint64_t)(size*4), found); \ } define_benchmark_find_last_sub(be, uint8_t) @@ -1102,24 +1120,24 @@ int main() if (mf.fd < 0) { - (void) fprintf(stderr, "can't open %s for reading\n", file); + (void)fprintf_s(stderr, "can't open %s for reading\n", file); return 1; } if (mf.size == 0) { - (void) fprintf(stderr, "fstat error! [%s]\n", strerror(errno)); + (void)fprintf_s(stderr, "fstat error! [%s]\n", strerror(errno)); return 1; } if (mf.src == MAP_FAILED) { - (void) fprintf(stderr, "mmap error! [%s]\n", strerror(errno)); + (void)fprintf_s(stderr, "mmap error! [%s]\n", strerror(errno)); return 1; } nrows = (mf.size / blklen); if (nrows != 251) { - (void) fprintf(stderr, "Expecting 251 items, got instead: %" PRIu64 "\n", nrows); + (void)fprintf_s(stderr, "Expecting 251 items, got instead: %" PRIu64 "\n", nrows); return 1; } @@ -1189,9 +1207,9 @@ int main() int e = munmap_binfile(mf); if (e != 0) { - (void) fprintf(stderr, "Got %d error while unmapping the file\n", e); + (void)fprintf_s(stderr, "Got %d error while unmapping the file\n", e); return 1; } return errors; -} \ No newline at end of file +} diff --git a/c/test/test_binsearch_col.c b/c/test/test_binsearch_col.c index 42f36cc..7e904f7 100644 --- a/c/test/test_binsearch_col.c +++ b/c/test/test_binsearch_col.c @@ -1,6 +1,24 @@ -// Nicola Asuni +// BinSearch +// +// test_binsearch_col.h +// +// @category Test +// @author Nicola Asuni +// @link https://github.com/tecnickcom/binsearch +// @license MIT (see LICENSE file) +// @copyright (c) 2017-2025 Nicola Asuni - Tecnick.com + +#ifdef __STDC__LIB_EXT1__ +#define __STDC_WANT_LIB_EXT1__ 1 +#else +// Ignore clang-tidy warning for deprecated or unsafe buffer handling +// NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling) +#define fprintf_s fprintf +#endif #include +#include +#include #include #include #include @@ -21,7 +39,7 @@ typedef struct t_test_col_uint8_t uint64_t foundLast; uint64_t foundLFirst; uint64_t foundLLast; -} __attribute__((packed)) __attribute__((aligned(128))) t_test_col_uint8_t; +} __attribute__((packed,aligned(128))) t_test_col_uint8_t; // bytes=1, bitstart=0, bitend=7, bitmask=00000000000000ff, rshift=0 @@ -109,7 +127,6 @@ static const t_test_col_uint8_t test_col_data_sub_uint8_t[] = { 150, 251, 0x70, 251, 149, 150, 251, 149, 150}, }; - typedef struct t_test_col_uint16_t { uint64_t first; @@ -121,7 +138,7 @@ typedef struct t_test_col_uint16_t uint64_t foundLast; uint64_t foundLFirst; uint64_t foundLLast; -} __attribute__((packed)) __attribute__((aligned(128))) t_test_col_uint16_t; +} __attribute__((packed,aligned(128))) t_test_col_uint16_t; // bytes=2, bitstart=0, bitend=15, bitmask=000000000000ffff, rshift=0 @@ -220,7 +237,7 @@ typedef struct t_test_col_uint32_t uint64_t foundLast; uint64_t foundLFirst; uint64_t foundLLast; -} __attribute__((packed)) __attribute__((aligned(128))) t_test_col_uint32_t; +} __attribute__((packed,aligned(128))) t_test_col_uint32_t; // bytes=4, bitstart=8, bitend=23, bitmask=0000000000ffffff, rshift=8 @@ -320,7 +337,7 @@ typedef struct t_test_col_uint64_t uint64_t foundLast; uint64_t foundLFirst; uint64_t foundLLast; -} __attribute__((packed)) __attribute__((aligned(128))) t_test_col_uint64_t; +} __attribute__((packed,aligned(128))) t_test_col_uint64_t; // bytes=8, bitstart=16, bitend=47, bitmask=0000ffffffffffff, rshift=16 @@ -427,17 +444,17 @@ int test_col_find_first_##T(mmfile_t mf) \ ffound = col_find_first_##T(src, &first, &last, test_col_data_##T[i].search); \ if (ffound != test_col_data_##T[i].foundFirst) \ { \ - (void) fprintf(stderr, "%s (%d) Expected found %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_##T[i].foundFirst, ffound); \ + (void)fprintf_s(stderr, "%s (%d) Expected found %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_##T[i].foundFirst, ffound); \ ++errors; \ } \ if (first != test_col_data_##T[i].foundFFirst) \ { \ - (void) fprintf(stderr, "%s (%d) Expected first %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_##T[i].foundFFirst, first); \ + (void)fprintf_s(stderr, "%s (%d) Expected first %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_##T[i].foundFFirst, first); \ ++errors; \ } \ if (last != test_col_data_##T[i].foundFLast) \ { \ - (void) fprintf(stderr, "%s (%d) Expected last %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_##T[i].foundFLast, last); \ + (void)fprintf_s(stderr, "%s (%d) Expected last %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_##T[i].foundFLast, last); \ ++errors; \ } \ numitems = (test_col_data_##T[i].foundLast - test_col_data_##T[i].foundFirst); \ @@ -451,7 +468,7 @@ int test_col_find_first_##T(mmfile_t mf) \ } \ if (counter != numitems) \ { \ - (void) fprintf(stderr, "%s HAS_NEXT (%d) Expected %" PRIu64 ", got %" PRIu64 "\n", __func__, i, numitems, counter); \ + (void)fprintf_s(stderr, "%s HAS_NEXT (%d) Expected %" PRIu64 ", got %" PRIu64 "\n", __func__, i, numitems, counter); \ ++errors; \ } \ } \ @@ -460,17 +477,17 @@ int test_col_find_first_##T(mmfile_t mf) \ lfound = col_find_first_sub_##T(src, bitstart, bitend, &first, &last, test_col_data_sub_##T[i].search); \ if (lfound != test_col_data_sub_##T[i].foundFirst) \ { \ - (void) fprintf(stderr, "%s SUB (%d) Expected found %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_sub_##T[i].foundFirst, lfound); \ + (void)fprintf_s(stderr, "%s SUB (%d) Expected found %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_sub_##T[i].foundFirst, lfound); \ ++errors; \ } \ if (first != test_col_data_sub_##T[i].foundFFirst) \ { \ - (void) fprintf(stderr, "%s SUB (%d) Expected first %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_sub_##T[i].foundFFirst, first); \ + (void)fprintf_s(stderr, "%s SUB (%d) Expected first %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_sub_##T[i].foundFFirst, first); \ ++errors; \ } \ if (last != test_col_data_sub_##T[i].foundFLast) \ { \ - (void) fprintf(stderr, "%s SUB (%d) Expected last %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_sub_##T[i].foundFLast, last); \ + (void)fprintf_s(stderr, "%s SUB (%d) Expected last %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_sub_##T[i].foundFLast, last); \ ++errors; \ } \ numitems = (test_col_data_sub_##T[i].foundLast - test_col_data_sub_##T[i].foundFirst); \ @@ -484,7 +501,7 @@ int test_col_find_first_##T(mmfile_t mf) \ } \ if (counter != numitems) \ { \ - (void) fprintf(stderr, "%s HAS_NEXT_SUB (%d) Expected %" PRIu64 ", got %" PRIu64 "\n", __func__, i, numitems, counter); \ + (void)fprintf_s(stderr, "%s HAS_NEXT_SUB (%d) Expected %" PRIu64 ", got %" PRIu64 "\n", __func__, i, numitems, counter); \ ++errors; \ } \ } \ @@ -514,17 +531,17 @@ int test_col_find_last_##T(mmfile_t mf) \ ffound = col_find_last_##T(src, &first, &last, test_col_data_##T[i].search); \ if (ffound != test_col_data_##T[i].foundLast) \ { \ - (void) fprintf(stderr, "%s (%d) Expected found %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_##T[i].foundLast, ffound); \ + (void)fprintf_s(stderr, "%s (%d) Expected found %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_##T[i].foundLast, ffound); \ ++errors; \ } \ if (first != test_col_data_##T[i].foundLFirst) \ { \ - (void) fprintf(stderr, "%s (%d) Expected first %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_##T[i].foundLFirst, first); \ + (void)fprintf_s(stderr, "%s (%d) Expected first %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_##T[i].foundLFirst, first); \ ++errors; \ } \ if (last != test_col_data_##T[i].foundLLast) \ { \ - (void) fprintf(stderr, "%s (%d) Expected last %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_##T[i].foundLLast, last); \ + (void)fprintf_s(stderr, "%s (%d) Expected last %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_##T[i].foundLLast, last); \ ++errors; \ } \ numitems = (test_col_data_##T[i].foundLast - test_col_data_##T[i].foundFirst); \ @@ -538,7 +555,7 @@ int test_col_find_last_##T(mmfile_t mf) \ } \ if (counter != numitems) \ { \ - (void) fprintf(stderr, "%s HAS_PREV (%d) Expected %" PRIu64 ", got %" PRIu64 "\n", __func__, i, numitems, counter); \ + (void)fprintf_s(stderr, "%s HAS_PREV (%d) Expected %" PRIu64 ", got %" PRIu64 "\n", __func__, i, numitems, counter); \ ++errors; \ } \ } \ @@ -547,17 +564,17 @@ int test_col_find_last_##T(mmfile_t mf) \ lfound = col_find_last_sub_##T(src, bitstart, bitend, &first, &last, test_col_data_sub_##T[i].search); \ if (lfound != test_col_data_sub_##T[i].foundLast) \ { \ - (void) fprintf(stderr, "%s SUB (%d) Expected found %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_sub_##T[i].foundLast, lfound); \ + (void)fprintf_s(stderr, "%s SUB (%d) Expected found %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_sub_##T[i].foundLast, lfound); \ ++errors; \ } \ if (first != test_col_data_sub_##T[i].foundLFirst) \ { \ - (void) fprintf(stderr, "%s SUB (%d) Expected first %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_sub_##T[i].foundLFirst, first); \ + (void)fprintf_s(stderr, "%s SUB (%d) Expected first %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_sub_##T[i].foundLFirst, first); \ ++errors; \ } \ if (last != test_col_data_sub_##T[i].foundLLast) \ { \ - (void) fprintf(stderr, "%s SUB (%d) Expected last %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_sub_##T[i].foundLLast, last); \ + (void)fprintf_s(stderr, "%s SUB (%d) Expected last %" PRIx64 ", got %" PRIx64 "\n", __func__, i, test_col_data_sub_##T[i].foundLLast, last); \ ++errors; \ } \ numitems = (test_col_data_sub_##T[i].foundLast - test_col_data_sub_##T[i].foundFirst); \ @@ -571,7 +588,7 @@ int test_col_find_last_##T(mmfile_t mf) \ } \ if (counter != numitems) \ { \ - (void) fprintf(stderr, "%s HAS_PREV_SUB (%d) Expected %" PRIu64 ", got %" PRIu64 "\n", __func__, i, numitems, counter); \ + (void)fprintf_s(stderr, "%s HAS_PREV_SUB (%d) Expected %" PRIu64 ", got %" PRIu64 "\n", __func__, i, numitems, counter); \ ++errors; \ } \ } \ @@ -588,7 +605,7 @@ define_test_col_find_last(uint64_t) uint64_t get_time() { struct timespec t; - (void) timespec_get(&t, TIME_UTC); + (void)timespec_get(&t, TIME_UTC); return (((uint64_t)t.tv_sec * 1000000000) + (uint64_t)t.tv_nsec); } @@ -610,7 +627,7 @@ void benchmark_col_find_first_##T(mmfile_t mf) \ found = col_find_first_##T(src, &first, &last, test_col_data_##T[4].search); \ } \ tend = get_time(); \ - (void) fprintf(stdout, " * %s : %lu ns/op (%" PRIx64 ")\n", __func__, (tend - tstart)/(uint64_t)(size*4), found); \ + (void)fprintf_s(stdout, " * %s : %lu ns/op (%" PRIx64 ")\n", __func__, (tend - tstart)/(uint64_t)(size*4), found); \ } define_benchmark_col_find_first(uint8_t) @@ -636,7 +653,7 @@ void benchmark_col_find_last_##T(mmfile_t mf) \ found = col_find_last_##T(src, &first, &last, test_col_data_##T[4].search); \ } \ tend = get_time(); \ - (void) fprintf(stdout, " * %s : %lu ns/op (%" PRIx64 ")\n", __func__, (tend - tstart)/(uint64_t)(size*4), found); \ + (void)fprintf_s(stdout, " * %s : %lu ns/op (%" PRIx64 ")\n", __func__, (tend - tstart)/(uint64_t)(size*4), found); \ } define_benchmark_col_find_last(uint8_t) @@ -665,7 +682,7 @@ void benchmark_col_find_first_sub_##T(mmfile_t mf) \ found = col_find_first_sub_##T(src, bitstart, bitend, &first, &last, test_col_data_##T[4].search); \ } \ tend = get_time(); \ - (void) fprintf(stdout, " * %s : %lu ns/op (%" PRIx64 ")\n", __func__, (tend - tstart)/(uint64_t)(size*4), found); \ + (void)fprintf_s(stdout, " * %s : %lu ns/op (%" PRIx64 ")\n", __func__, (tend - tstart)/(uint64_t)(size*4), found); \ } define_benchmark_col_find_first_sub(uint8_t) @@ -694,7 +711,7 @@ void benchmark_col_find_last_sub_##T(mmfile_t mf) \ found = col_find_last_sub_##T(src, bitstart, bitend, &first, &last, test_col_data_##T[4].search); \ } \ tend = get_time(); \ - (void) fprintf(stdout, " * %s : %lu ns/op (%" PRIx64 ")\n", __func__, (tend - tstart)/(uint64_t)(size*4), found); \ + (void)fprintf_s(stdout, " * %s : %lu ns/op (%" PRIx64 ")\n", __func__, (tend - tstart)/(uint64_t)(size*4), found); \ } define_benchmark_col_find_last_sub(uint8_t) @@ -718,23 +735,23 @@ int main() if (mf.fd < 0) { - (void) fprintf(stderr, "can't open %s for reading\n", file); + (void)fprintf_s(stderr, "can't open %s for reading\n", file); return 1; } if (mf.size == 0) { - (void) fprintf(stderr, "fstat error! [%s]\n", strerror(errno)); + (void)fprintf_s(stderr, "fstat error! [%s]\n", strerror(errno)); return 1; } if (mf.src == MAP_FAILED) { - (void) fprintf(stderr, "mmap error! [%s]\n", strerror(errno)); + (void)fprintf_s(stderr, "mmap error! [%s]\n", strerror(errno)); return 1; } if (mf.size != 3776) { - (void) fprintf(stderr, "Expecting 37776 bytes, got instead: %" PRIu64 "\n", mf.size); + (void)fprintf_s(stderr, "Expecting 37776 bytes, got instead: %" PRIu64 "\n", mf.size); return 1; } @@ -768,9 +785,9 @@ int main() int e = munmap_binfile(mf); if (e != 0) { - (void) fprintf(stderr, "Got %d error while unmapping the file\n", e); + (void)fprintf_s(stderr, "Got %d error while unmapping the file\n", e); return 1; } return errors; -} \ No newline at end of file +} diff --git a/c/test/test_binsearch_file.c b/c/test/test_binsearch_file.c index bd20e19..ce9687f 100644 --- a/c/test/test_binsearch_file.c +++ b/c/test/test_binsearch_file.c @@ -1,15 +1,25 @@ -// binsearch +// BinSearch // -// test_binsearch_file.c +// test_binsearch_file.h // // @category Test // @author Nicola Asuni // @link https://github.com/tecnickcom/binsearch -// @license MIT [LICENSE](https://raw.githubusercontent.com/tecnickcom/variantkey/main/LICENSE) +// @license MIT (see LICENSE file) +// @copyright (c) 2017-2025 Nicola Asuni - Tecnick.com + +#ifdef __STDC__LIB_EXT1__ +#define __STDC_WANT_LIB_EXT1__ 1 +#else +// Ignore clang-tidy warning for deprecated or unsafe buffer handling +// NOLINTNEXTLINE(clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling) +#define fprintf_s fprintf +#endif #include +#include +#include #include -#include #include #include #include "../src/numkey/binsearch.h" @@ -20,7 +30,7 @@ int test_mmap_binfile_error(const char* file) mmap_binfile(file, &mf); if (mf.src != MAP_FAILED) { - (void) fprintf(stderr, "An mmap error was expected\n"); + (void)fprintf_s(stderr, "An mmap error was expected\n"); return 1; } return 0; @@ -32,7 +42,7 @@ int test_munmap_binfile_error() int e = munmap_binfile(mf); if (e == 0) { - (void) fprintf(stderr, "An mummap error was expected\n"); + (void)fprintf_s(stderr, "An mummap error was expected\n"); return 1; } return 0; @@ -49,58 +59,58 @@ int test_map_file_arrow() mmap_binfile(file, &mf); if (mf.fd < 0) { - (void) fprintf(stderr, "%s can't open %s for reading\n", __func__, file); + (void)fprintf_s(stderr, "%s can't open %s for reading\n", __func__, file); return 1; } if (mf.size == 0) { - (void) fprintf(stderr, "%s fstat error! [%s]\n", __func__, strerror(errno)); + (void)fprintf_s(stderr, "%s fstat error! [%s]\n", __func__, strerror(errno)); return 1; } if (mf.src == MAP_FAILED) { - (void) fprintf(stderr, "%s mmap error! [%s]\n", __func__, strerror(errno)); + (void)fprintf_s(stderr, "%s mmap error! [%s]\n", __func__, strerror(errno)); return 1; } if (mf.size != 730) { - (void) fprintf(stderr, "%s mf.size : Expecting 730 bytes, got instead: %" PRIu64 "\n", __func__, mf.size); + (void)fprintf_s(stderr, "%s mf.size : Expecting 730 bytes, got instead: %" PRIu64 "\n", __func__, mf.size); errors++; } if (mf.doffset != 376) { - (void) fprintf(stderr, "%s mf.doffset : Expecting 376 bytes, got instead: %" PRIu64 "\n", __func__, mf.doffset); + (void)fprintf_s(stderr, "%s mf.doffset : Expecting 376 bytes, got instead: %" PRIu64 "\n", __func__, mf.doffset); errors++; } if (mf.dlength != 136) { - (void) fprintf(stderr, "%s mf.dlength : Expecting 136 bytes, got instead: %" PRIu64 "\n", __func__, mf.dlength); + (void)fprintf_s(stderr, "%s mf.dlength : Expecting 136 bytes, got instead: %" PRIu64 "\n", __func__, mf.dlength); errors++; } if (mf.nrows != 11) { - (void) fprintf(stderr, "%s mf.nrows : Expecting 11 items, got instead: %" PRIu64 "\n", __func__, mf.nrows); + (void)fprintf_s(stderr, "%s mf.nrows : Expecting 11 items, got instead: %" PRIu64 "\n", __func__, mf.nrows); errors++; } if (mf.ncols != 2) { - (void) fprintf(stderr, "%s mf.ncols : Expecting 2 items, got instead: %" PRIu8 "\n", __func__, mf.ncols); + (void)fprintf_s(stderr, "%s mf.ncols : Expecting 2 items, got instead: %" PRIu8 "\n", __func__, mf.ncols); errors++; } if (mf.index[0] != 376) { - (void) fprintf(stderr, "%s mf.index[0] : Expecting 376 bytes, got instead: %" PRIu64 "\n", __func__, mf.index[0]); + (void)fprintf_s(stderr, "%s mf.index[0] : Expecting 376 bytes, got instead: %" PRIu64 "\n", __func__, mf.index[0]); errors++; } if (mf.index[1] != 424) { - (void) fprintf(stderr, "%s mf.index[1] : Expecting 424 bytes, got instead: %" PRIu64 "\n", __func__, mf.index[1]); + (void)fprintf_s(stderr, "%s mf.index[1] : Expecting 424 bytes, got instead: %" PRIu64 "\n", __func__, mf.index[1]); errors++; } int e = munmap_binfile(mf); if (e != 0) { - (void) fprintf(stderr, "%s Got %d error while unmapping the file\n", __func__, e); + (void)fprintf_s(stderr, "%s Got %d error while unmapping the file\n", __func__, e); errors++; } return errors; @@ -117,58 +127,58 @@ int test_map_file_feather() mmap_binfile(file, &mf); if (mf.fd < 0) { - (void) fprintf(stderr, "%s can't open %s for reading\n", __func__, file); + (void)fprintf_s(stderr, "%s can't open %s for reading\n", __func__, file); return 1; } if (mf.size == 0) { - (void) fprintf(stderr, "%s fstat error! [%s]\n", __func__, strerror(errno)); + (void)fprintf_s(stderr, "%s fstat error! [%s]\n", __func__, strerror(errno)); return 1; } if (mf.src == MAP_FAILED) { - (void) fprintf(stderr, "%s mmap error! [%s]\n", __func__, strerror(errno)); + (void)fprintf_s(stderr, "%s mmap error! [%s]\n", __func__, strerror(errno)); return 1; } if (mf.size != 384) { - (void) fprintf(stderr, "%s mf.size : Expecting 384 bytes, got instead: %" PRIu64 "\n", __func__, mf.size); + (void)fprintf_s(stderr, "%s mf.size : Expecting 384 bytes, got instead: %" PRIu64 "\n", __func__, mf.size); errors++; } if (mf.doffset != 8) { - (void) fprintf(stderr, "%s mf.doffset : Expecting 8 bytes, got instead: %" PRIu64 "\n", __func__, mf.doffset); + (void)fprintf_s(stderr, "%s mf.doffset : Expecting 8 bytes, got instead: %" PRIu64 "\n", __func__, mf.doffset); errors++; } if (mf.dlength != 136) { - (void) fprintf(stderr, "%s mf.dlength : Expecting 136 bytes, got instead: %" PRIu64 "\n", __func__, mf.dlength); + (void)fprintf_s(stderr, "%s mf.dlength : Expecting 136 bytes, got instead: %" PRIu64 "\n", __func__, mf.dlength); errors++; } if (mf.nrows != 11) { - (void) fprintf(stderr, "%s mf.nrows : Expecting 11 items, got instead: %" PRIu64 "\n", __func__, mf.nrows); + (void)fprintf_s(stderr, "%s mf.nrows : Expecting 11 items, got instead: %" PRIu64 "\n", __func__, mf.nrows); errors++; } if (mf.ncols != 2) { - (void) fprintf(stderr, "%s mf.ncols : Expecting 2 items, got instead: %" PRIu8 "\n", __func__, mf.ncols); + (void)fprintf_s(stderr, "%s mf.ncols : Expecting 2 items, got instead: %" PRIu8 "\n", __func__, mf.ncols); errors++; } if (mf.index[0] != 8) { - (void) fprintf(stderr, "%s mf.index[0] : Expecting 8 bytes, got instead: %" PRIu64 "\n", __func__, mf.index[0]); + (void)fprintf_s(stderr, "%s mf.index[0] : Expecting 8 bytes, got instead: %" PRIu64 "\n", __func__, mf.index[0]); errors++; } if (mf.index[1] != 56) { - (void) fprintf(stderr, "%s mf.index[1] : Expecting 56 bytes, got instead: %" PRIu64 "\n", __func__, mf.index[1]); + (void)fprintf_s(stderr, "%s mf.index[1] : Expecting 56 bytes, got instead: %" PRIu64 "\n", __func__, mf.index[1]); errors++; } int e = munmap_binfile(mf); if (e != 0) { - (void) fprintf(stderr, "%s Got %d error while unmapping the file\n", __func__, e); + (void)fprintf_s(stderr, "%s Got %d error while unmapping the file\n", __func__, e); errors++; } return errors; @@ -182,58 +192,58 @@ int test_map_file_binsrc() mmap_binfile(file, &mf); if (mf.fd < 0) { - (void) fprintf(stderr, "%s can't open %s for reading\n", __func__, file); + (void)fprintf_s(stderr, "%s can't open %s for reading\n", __func__, file); return 1; } if (mf.size == 0) { - (void) fprintf(stderr, "%s fstat error! [%s]\n", __func__, strerror(errno)); + (void)fprintf_s(stderr, "%s fstat error! [%s]\n", __func__, strerror(errno)); return 1; } if (mf.src == MAP_FAILED) { - (void) fprintf(stderr, "%s mmap error! [%s]\n", __func__, strerror(errno)); + (void)fprintf_s(stderr, "%s mmap error! [%s]\n", __func__, strerror(errno)); return 1; } if (mf.size != 176) { - (void) fprintf(stderr, "%s mf.size : Expecting 176 bytes, got instead: %" PRIu64 "\n", __func__, mf.size); + (void)fprintf_s(stderr, "%s mf.size : Expecting 176 bytes, got instead: %" PRIu64 "\n", __func__, mf.size); errors++; } if (mf.doffset != 40) { - (void) fprintf(stderr, "%s mf.doffset : Expecting 40 bytes, got instead: %" PRIu64 "\n", __func__, mf.doffset); + (void)fprintf_s(stderr, "%s mf.doffset : Expecting 40 bytes, got instead: %" PRIu64 "\n", __func__, mf.doffset); errors++; } if (mf.dlength != 136) { - (void) fprintf(stderr, "%s mf.dlength : Expecting 136 bytes, got instead: %" PRIu64 "\n", __func__, mf.dlength); + (void)fprintf_s(stderr, "%s mf.dlength : Expecting 136 bytes, got instead: %" PRIu64 "\n", __func__, mf.dlength); errors++; } if (mf.nrows != 11) { - (void) fprintf(stderr, "%s mf.nrows : Expecting 11 items, got instead: %" PRIu64 "\n", __func__, mf.nrows); + (void)fprintf_s(stderr, "%s mf.nrows : Expecting 11 items, got instead: %" PRIu64 "\n", __func__, mf.nrows); errors++; } if (mf.ncols != 2) { - (void) fprintf(stderr, "%s mf.ncols : Expecting 2 items, got instead: %" PRIu8 "\n", __func__, mf.ncols); + (void)fprintf_s(stderr, "%s mf.ncols : Expecting 2 items, got instead: %" PRIu8 "\n", __func__, mf.ncols); errors++; } if (mf.index[0] != 40) { - (void) fprintf(stderr, "%s mf.index[0] : Expecting 40 bytes, got instead: %" PRIu64 "\n", __func__, mf.index[0]); + (void)fprintf_s(stderr, "%s mf.index[0] : Expecting 40 bytes, got instead: %" PRIu64 "\n", __func__, mf.index[0]); errors++; } if (mf.index[1] != 88) { - (void) fprintf(stderr, "%s mf.index[1] : Expecting 88 bytes, got instead: %" PRIu64 "\n", __func__, mf.index[1]); + (void)fprintf_s(stderr, "%s mf.index[1] : Expecting 88 bytes, got instead: %" PRIu64 "\n", __func__, mf.index[1]); errors++; } int e = munmap_binfile(mf); if (e != 0) { - (void) fprintf(stderr, "%s Got %d error while unmapping the file\n", __func__, e); + (void)fprintf_s(stderr, "%s Got %d error while unmapping the file\n", __func__, e); errors++; } return errors; @@ -247,48 +257,48 @@ int test_map_file_col() mmap_binfile(file, &mf); if (mf.fd < 0) { - (void) fprintf(stderr, "%s can't open %s for reading\n", __func__, file); + (void)fprintf_s(stderr, "%s can't open %s for reading\n", __func__, file); return 1; } if (mf.size == 0) { - (void) fprintf(stderr, "%s fstat error! [%s]\n", __func__, strerror(errno)); + (void)fprintf_s(stderr, "%s fstat error! [%s]\n", __func__, strerror(errno)); return 1; } if (mf.src == MAP_FAILED) { - (void) fprintf(stderr, "%s mmap error! [%s]\n", __func__, strerror(errno)); + (void)fprintf_s(stderr, "%s mmap error! [%s]\n", __func__, strerror(errno)); return 1; } if (mf.size != 3776) { - (void) fprintf(stderr, "%s mf.size : Expecting 3776 bytes, got instead: %" PRIu64 "\n", __func__, mf.size); + (void)fprintf_s(stderr, "%s mf.size : Expecting 3776 bytes, got instead: %" PRIu64 "\n", __func__, mf.size); errors++; } if (mf.doffset != 0) { - (void) fprintf(stderr, "%s mf.doffset : Expecting 0 bytes, got instead: %" PRIu64 "\n", __func__, mf.doffset); + (void)fprintf_s(stderr, "%s mf.doffset : Expecting 0 bytes, got instead: %" PRIu64 "\n", __func__, mf.doffset); errors++; } if (mf.dlength != 3776) { - (void) fprintf(stderr, "%s mf.dlength : Expecting 3776 bytes, got instead: %" PRIu64 "\n", __func__, mf.dlength); + (void)fprintf_s(stderr, "%s mf.dlength : Expecting 3776 bytes, got instead: %" PRIu64 "\n", __func__, mf.dlength); errors++; } if (mf.nrows != 0) { - (void) fprintf(stderr, "%s mf.nrows : Expecting 0 items, got instead: %" PRIu64 "\n", __func__, mf.nrows); + (void)fprintf_s(stderr, "%s mf.nrows : Expecting 0 items, got instead: %" PRIu64 "\n", __func__, mf.nrows); errors++; } if (mf.ncols != 0) { - (void) fprintf(stderr, "%s mf.ncols : Expecting 0 items, got instead: %" PRIu8 "\n", __func__, mf.ncols); + (void)fprintf_s(stderr, "%s mf.ncols : Expecting 0 items, got instead: %" PRIu8 "\n", __func__, mf.ncols); errors++; } int e = munmap_binfile(mf); if (e != 0) { - (void) fprintf(stderr, "%s Got %d error while unmapping the file\n", __func__, e); + (void)fprintf_s(stderr, "%s Got %d error while unmapping the file\n", __func__, e); errors++; } return errors; @@ -307,4 +317,4 @@ int main() errors += test_map_file_col(); return errors; -} \ No newline at end of file +} diff --git a/c/test/test_countrykey.c b/c/test/test_countrykey.c index 5d453da..05a79e8 100644 --- a/c/test/test_countrykey.c +++ b/c/test/test_countrykey.c @@ -11,8 +11,8 @@ #include #include -#include #include +#include #include #include "../src/numkey/countrykey.h" diff --git a/c/test/test_example.c b/c/test/test_example.c index 7d6b495..58ce7b3 100644 --- a/c/test/test_example.c +++ b/c/test/test_example.c @@ -2,9 +2,8 @@ // https://github.com/Vonage/numkey #include +#include #include -#include -#include #include "../src/numkey/numkey.h" int main() diff --git a/c/test/test_hex.c b/c/test/test_hex.c index 2d22fd0..fb2a04e 100644 --- a/c/test/test_hex.c +++ b/c/test/test_hex.c @@ -1,19 +1,16 @@ -// NumKey -// // test_hex.c // // @category Test // @author Nicola Asuni -// @link https://github.com/Vonage/variantkey +// @link https://github.com/tecnickcom/variantkey // @license MIT [LICENSE](https://raw.githubusercontent.com/tecnickcom/variantkey/main/LICENSE) // Test for hex -#include #include +#include #include #include -#include #include #include "../src/numkey/hex.h" @@ -92,4 +89,4 @@ int main() benchmark_parse_hex_uint64_t(); return errors; -} \ No newline at end of file +} diff --git a/c/test/test_numkey.c b/c/test/test_numkey.c index ee14ff4..458824e 100644 --- a/c/test/test_numkey.c +++ b/c/test/test_numkey.c @@ -11,8 +11,8 @@ #include #include -#include #include +#include #include #include "../src/numkey/numkey.h" diff --git a/c/test/test_prefixkey.c b/c/test/test_prefixkey.c index 02e81c3..b37639c 100644 --- a/c/test/test_prefixkey.c +++ b/c/test/test_prefixkey.c @@ -10,6 +10,7 @@ // Test for prefixey #include +#include #include #include #include diff --git a/c/test/test_set.c b/c/test/test_set.c index a5e7da8..c059b99 100644 --- a/c/test/test_set.c +++ b/c/test/test_set.c @@ -1,5 +1,3 @@ -// NumKey -// // test_set.c // // @category Test @@ -9,11 +7,9 @@ // Test for set -#include #include +#include #include -#include -#include #include #include "../src/numkey/set.h" @@ -259,4 +255,4 @@ int main() benchmark_sort_uint64_t(); return errors; -} \ No newline at end of file +} diff --git a/cgo/Makefile b/cgo/Makefile index f93d7c6..89da51c 100644 --- a/cgo/Makefile +++ b/cgo/Makefile @@ -50,7 +50,7 @@ GOFMT=$(shell which gofmt) GOTEST=$(GO) test GODOC=GOPATH=$(GOPATH) $(shell which godoc) GOLANGCILINT=$(BINUTIL)/golangci-lint -GOLANGCILINTVERSION=v2.4.0 +GOLANGCILINTVERSION=v2.5.0 # Directory containing the source code SRCDIR=./src diff --git a/cgo/src/numkey.go b/cgo/src/numkey.go index 49b8cf0..46b883b 100644 --- a/cgo/src/numkey.go +++ b/cgo/src/numkey.go @@ -8,7 +8,7 @@ package numkey /* -#cgo CFLAGS: -O3 -pedantic -std=c99 -Wextra -Wno-strict-prototypes -Wcast-align -Wundef -Wformat -Wformat-security -Wshadow +#cgo CFLAGS: -O3 -pedantic -std=c2x -Wextra -Wno-strict-prototypes -Wcast-align -Wundef -Wformat -Wformat-security -Wshadow #include #include #include "../../c/src/numkey/hex.h" diff --git a/go/Makefile b/go/Makefile index d6698d9..42058e5 100644 --- a/go/Makefile +++ b/go/Makefile @@ -50,7 +50,7 @@ GOFMT=$(shell which gofmt) GOTEST=$(GO) test GODOC=GOPATH=$(GOPATH) $(shell which godoc) GOLANGCILINT=$(BINUTIL)/golangci-lint -GOLANGCILINTVERSION=v2.4.0 +GOLANGCILINTVERSION=v2.5.0 # Directory containing the source code SRCDIR=./src diff --git a/java/build.gradle b/java/build.gradle index 18226e2..e21c5af 100644 --- a/java/build.gradle +++ b/java/build.gradle @@ -24,3 +24,9 @@ dependencies { tasks.named("test", Test.class).configure { useJUnitPlatform() } + +java { + toolchain { + languageVersion = JavaLanguageVersion.of(21) + } +} \ No newline at end of file diff --git a/java/gradle/wrapper/gradle-wrapper.properties b/java/gradle/wrapper/gradle-wrapper.properties index 2a84e18..2e11132 100644 --- a/java/gradle/wrapper/gradle-wrapper.properties +++ b/java/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-9.1.0-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/java/gradlew b/java/gradlew index ef07e01..adff685 100755 --- a/java/gradlew +++ b/java/gradlew @@ -114,7 +114,6 @@ case "$( uname )" in #( NONSTOP* ) nonstop=true ;; esac -CLASSPATH="\\\"\\\"" # Determine the Java command to use to start the JVM. @@ -172,7 +171,6 @@ fi # For Cygwin or MSYS, switch paths to Windows format before running java if "$cygwin" || "$msys" ; then APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) - CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) JAVACMD=$( cygpath --unix "$JAVACMD" ) @@ -212,7 +210,6 @@ DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ - -classpath "$CLASSPATH" \ -jar "$APP_HOME/gradle/wrapper/gradle-wrapper.jar" \ "$@" diff --git a/java/gradlew.bat b/java/gradlew.bat index db3a6ac..c4bdd3a 100644 --- a/java/gradlew.bat +++ b/java/gradlew.bat @@ -70,11 +70,10 @@ goto fail :execute @rem Setup the command line -set CLASSPATH= @rem Execute Gradle -"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -jar "%APP_HOME%\gradle\wrapper\gradle-wrapper.jar" %* :end @rem End local scope for the variables with windows NT shell diff --git a/python/numkey/pynumkey.c b/python/numkey/pynumkey.c index 0d6ecd2..d930223 100644 --- a/python/numkey/pynumkey.c +++ b/python/numkey/pynumkey.c @@ -127,7 +127,7 @@ static PyObject* py_decode_countrykey(PyObject *Py_UNUSED(ignored), PyObject *ar if (!PyArg_ParseTupleAndKeywords(args, keywds, "h", kwlist, &ck)) return NULL; char h[3]; - decode_countrykey(ck, &h); + decode_countrykey(ck, h); return PyBytes_FromString(h); } diff --git a/python/setup.py b/python/setup.py index 803aea6..84da26c 100644 --- a/python/setup.py +++ b/python/setup.py @@ -30,7 +30,7 @@ def run(self): setup( name="numkey", - version="1.6.57.1", + version="1.6.58.1", keywords=("numkey E.164 shortcode lvn did encoding"), description="NumKey Bindings for Python", long_description=read("../README.md"), @@ -48,7 +48,7 @@ def run(self): extra_compile_args=[ "-O3", "-pedantic", - "-std=c99", + "-std=c2x", "-Wall", "-Wextra", "-Wno-strict-prototypes",