Skip to content

Commit

Permalink
[AUTOPR] Tidy up code and update dependencies. (#27)
Browse files Browse the repository at this point in the history
* Tidy up source code and update dependencies

---------

Co-authored-by: nicolaasuni-vonage <[email protected]>
  • Loading branch information
github-actions[bot] and nicolaasuni-vonage authored Mar 15, 2024
1 parent c345825 commit 962040f
Show file tree
Hide file tree
Showing 20 changed files with 286 additions and 347 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
- name: set RELEASE number
run: echo ${GITHUB_RUN_NUMBER} > RELEASE
- name: test
run: cd c && make version test build
run: cd c && make version build

cgo:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.5.26
1.6.0
3 changes: 2 additions & 1 deletion c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,8 @@ testcpp:
# use clang-tidy
.PHONY: tidy
tidy:
clang-tidy -checks='*,-llvm-header-guard,-llvm-include-order,-android-cloexec-open,-hicpp-no-assembler,-hicpp-signed-bitwise,-clang-analyzer-alpha.*' -header-filter=.* -p . src/numkey/*.h nk/*.c test/*.c
clang-tidy -checks='*,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,-readability-function-cognitive-complexity,-altera-struct-pack-align,-altera-id-dependent-backward-branch,-bugprone-easily-swappable-parameters,-altera-unroll-loops,-readability-isolate-declaration,-llvmlibc-restrict-system-libc-headers,-readability-identifier-length,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-llvm-header-guard,-llvm-include-order,-android-cloexec-open,-hicpp-no-assembler,-hicpp-signed-bitwise,-clang-analyzer-alpha.*' -header-filter=.* -p . src/numkey/*.h nk/*.c
clang-tidy -checks='*,-concurrency-mt-unsafe,-clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling,-readability-function-cognitive-complexity,-altera-struct-pack-align,-altera-id-dependent-backward-branch,-bugprone-easily-swappable-parameters,-altera-unroll-loops,-readability-isolate-declaration,-llvmlibc-restrict-system-libc-headers,-readability-identifier-length,-cppcoreguidelines-avoid-magic-numbers,-readability-magic-numbers,-llvm-header-guard,-llvm-include-order,-android-cloexec-open,-hicpp-no-assembler,-hicpp-signed-bitwise,-clang-analyzer-alpha.*' -header-filter=.* -p . test/*.c

# Remove all installed files (excluding configuration files)
.PHONY: uninstall
Expand Down
2 changes: 1 addition & 1 deletion c/doc/Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -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.5.26
PROJECT_NUMBER = 1.6.0

# 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
Expand Down
4 changes: 2 additions & 2 deletions c/nk/nk.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ int main(int argc, char *argv[])
{
if (argc != 3)
{
fprintf(stderr, "NumKey Encoder %s\nUsage: nk COUNTRY NUMBER\n", VERSION);
(void) fprintf(stderr, "NumKey Encoder %s\nUsage: nk COUNTRY NUMBER\n", VERSION);
return 1;
}
fprintf(stdout, "%016" PRIx64, numkey(argv[1], argv[2], strlen(argv[2])));
(void) fprintf(stdout, "%016" PRIx64, numkey(argv[1], argv[2], strlen(argv[2])));
}
14 changes: 8 additions & 6 deletions c/src/numkey/binsearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// @category Libraries
// @author Nicola Asuni <[email protected]>
// @link https://github.com/tecnickcom/binsearch
// @license MIT (see https://raw.githubusercontent.com/tecnickcom/binsearch/main/LICENSE)
// @license MIT (see LICENSE file)
// @copyright (c) 2017-2024 Nicola Asuni - Tecnick.com

/**
Expand Down Expand Up @@ -179,7 +179,7 @@
#define order_le_uint64_t(x) (x) //!< Return LE uint64_t in the correct endianness order
#endif

#define MAXCOLS 256 //!< Maximum number of indexable columns
#define MAXCOLS 256 //!< Maximum number of columns indexable

/**
* Returns the absolute file address position of the specified item (binary block).
Expand Down Expand Up @@ -915,7 +915,7 @@ define_col_has_prev_sub(uint64_t)

static inline void parse_col_offset(mmfile_t *mf)
{
uint8_t i;
uint8_t i = 0;
uint64_t b = 0;
mf->index[0] = mf->doffset;
for (i = 0; i < mf->ncols; i++)
Expand All @@ -941,13 +941,13 @@ static inline void parse_info_binsrc(mmfile_t *mf)
mf->doffset = (uint64_t)9 + mf->ncols + ((8 - ((mf->ncols + 1) & 7)) & 7); // account for 8-byte padding
const uint64_t *op = (const uint64_t *)(mf->src + mf->doffset);
mf->nrows = *op++;
uint8_t i;
uint8_t i = 0;
for (i = 0; i < mf->ncols; i++)
{
mf->ctbytes[i] = *tp++;
mf->index[i] = *op++;
}
mf->doffset += ((mf->ncols + 1) * 8); // skip column offsets section
mf->doffset += ((uint64_t)(mf->ncols + 1) * 8); // skip column offsets section
mf->dlength -= mf->doffset;
}

Expand Down Expand Up @@ -1017,6 +1017,8 @@ static inline void mmap_binfile(const char *file, mmfile_t *mf)
case 0x0000000031414546: // magic number "FEA1" in LE
parse_info_feather(mf);
break;
default:
break;
}
parse_col_offset(mf);
}
Expand All @@ -1039,4 +1041,4 @@ static inline int munmap_binfile(mmfile_t mf)
return close(mf.fd);
}

#endif // NUMKEY_BINSEARCH_H
#endif // NUMKEY_BINSEARCH_H
8 changes: 4 additions & 4 deletions c/src/numkey/hex.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// @category Libraries
// @author Nicola Asuni <[email protected]>
// @link https://github.com/tecnickcom/variantkey
// @license MIT (see https://github.com/tecnickcom/variantkey/blob/main/LICENSE)
// @license MIT [LICENSE](https://raw.githubusercontent.com/tecnickcom/variantkey/main/LICENSE)

/**
* @file hex.h
Expand Down Expand Up @@ -44,8 +44,8 @@ static inline size_t hex_uint64_t(uint64_t n, char *str)
static inline uint64_t parse_hex_uint64_t(const char *s)
{
uint64_t v = 0;
uint8_t b;
size_t i;
uint8_t b = 0;
size_t i = 0;
for (i = 0; i < 16; i++)
{
b = s[i];
Expand All @@ -69,4 +69,4 @@ static inline uint64_t parse_hex_uint64_t(const char *s)
return v;
}

#endif // NUMKEY_HEX_H
#endif // NUMKEY_HEX_H
18 changes: 9 additions & 9 deletions c/src/numkey/numkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ static inline uint64_t encode_country(const char *country)
*/
static inline void decode_country(uint64_t nk, char *country)
{
country[0] = (char)((nk & NKBMASK_COUNTRY_FL) >> NKBSHIFT_COUNTRY_FL) + NKCSHIFT_CHAR;
country[1] = (char)((nk & NKBMASK_COUNTRY_SL) >> NKBSHIFT_COUNTRY_SL) + NKCSHIFT_CHAR;
country[0] = (char)(((nk & NKBMASK_COUNTRY_FL) >> NKBSHIFT_COUNTRY_FL) + NKCSHIFT_CHAR);
country[1] = (char)(((nk & NKBMASK_COUNTRY_SL) >> NKBSHIFT_COUNTRY_SL) + NKCSHIFT_CHAR);
country[2] = 0;
}

Expand All @@ -98,8 +98,8 @@ static inline void decode_country(uint64_t nk, char *country)
static inline uint64_t encode_number(const char *number, size_t size)
{
uint64_t num = 0;
uint8_t b;
size_t i, j = 0;
uint8_t b = 0;
size_t i = 0, j = 0;
uint64_t len = (uint64_t)(size);
if (size > NKNUMMAXLEN)
{
Expand Down Expand Up @@ -127,11 +127,11 @@ static inline size_t decode_number(uint64_t nk, char *number)
size_t size = (size_t)(nk & NKBMASK_LENGTH);
uint64_t num = ((nk & NKBMASK_NUMBER) >> NKBSHIFT_NUMBER);
int rem = 0;
int i;
for (i = (size - 1); i >= 0; i--)
int i = 0;
for (i = (int)(size - 1); i >= 0; i--)
{
rem = (num % 10);
number[i] = (rem + '0');
rem = (int)(num % 10);
number[i] = (char)(rem + '0');
num = (num / 10);
}
number[size] = 0;
Expand Down Expand Up @@ -166,7 +166,7 @@ static inline void decode_numkey(uint64_t nk, numkey_t *data)

static inline int8_t compare_uint64_t(uint64_t a, uint64_t b)
{
return (a < b) ? -1 : (a > b);
return (a < b) ? -1 : (a > b); //NOLINT:bugprone-narrowing-conversions,cppcoreguidelines-narrowing-conversions
}

/**
Expand Down
2 changes: 1 addition & 1 deletion c/src/numkey/prefixkey.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
static inline uint64_t prefixkey(const char *number, size_t size)
{
uint64_t num = 0;
uint8_t b;
uint8_t b = 0;
size_t i = 0;
if (size > PKNUMMAXLEN)
{
Expand Down
20 changes: 10 additions & 10 deletions c/src/numkey/set.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// @category Libraries
// @author Nicola Asuni <[email protected]>
// @link https://github.com/tecnickcom/variantkey
// @license MIT (see https://github.com/tecnickcom/variantkey/blob/main/LICENSE)
// @license MIT [LICENSE](https://raw.githubusercontent.com/tecnickcom/variantkey/main/LICENSE)

/**
* @file set.h
Expand Down Expand Up @@ -69,19 +69,19 @@
#define RADIX_SORT_ITERATION_BLOCK(A, B, BYTE, SHIFT) \
for (i = 0; i < nitems; i++) \
{ \
v = A[i]; \
B[c##BYTE[((v >> SHIFT) & 0xff)]++] = v; \
v = (A)[i]; \
(B)[c##BYTE[((v >> (SHIFT)) & 0xff)]++] = v; \
}

#define RADIX_SORT_ITERATION_INDEX_BLOCK(A, B, BYTE, SHIFT, ADX, BDX) \
for (i = 0; i < nitems; i++) \
{ \
v = A[i]; \
t##BYTE = ((v >> SHIFT) & 0xff); \
v = (A)[i]; \
t##BYTE = ((v >> (SHIFT)) & 0xff); \
j = c##BYTE[t##BYTE]; \
B[j] = v; \
(B)[j] = v; \
c##BYTE[t##BYTE]++; \
ADX = BDX; \
(ADX) = (BDX); \
}

/**
Expand Down Expand Up @@ -115,7 +115,7 @@ static inline void sort_uint64_t(uint64_t *arr, uint64_t *tmp, uint32_t nitems)
*/
static inline void order_uint64_t(uint64_t *arr, uint64_t *tmp, uint32_t *idx, uint32_t *tdx, uint32_t nitems)
{
uint32_t j;
uint32_t j = 0;
RADIX_SORT_COUNT_BLOCK
RADIX_SORT_ITERATION_INDEX_BLOCK(arr, tmp, 7, 0, tdx[j], i)
RADIX_SORT_ITERATION_INDEX_BLOCK(tmp, arr, 6, 8, idx[j], tdx[i])
Expand All @@ -136,7 +136,7 @@ static inline void order_uint64_t(uint64_t *arr, uint64_t *tmp, uint32_t *idx, u
static inline void reverse_uint64_t(uint64_t *arr, uint64_t nitems)
{
uint64_t *last = (arr + nitems);
uint64_t tmp;
uint64_t tmp = 0;
while ((arr != last) && (arr != --last))
{
tmp = *last;
Expand Down Expand Up @@ -243,4 +243,4 @@ static inline uint64_t *union_uint64_t(uint64_t *a_arr, uint64_t a_nitems, uint6
return o_arr;
}

#endif // NUMKEY_SET_H
#endif // NUMKEY_SET_H
Loading

0 comments on commit 962040f

Please sign in to comment.