diff --git a/.clang-format b/.clang-format index afe404a..db0a4e2 100644 --- a/.clang-format +++ b/.clang-format @@ -59,7 +59,7 @@ BreakConstructorInitializersBeforeComma: false BreakConstructorInitializers: BeforeColon BreakAfterJavaFieldAnnotations: false BreakStringLiterals: true -ColumnLimit: 100 +ColumnLimit: 120 CommentPragmas: '^ IWYU pragma:' CompactNamespaces: true ConstructorInitializerAllOnOneLineOrOnePerLine: true diff --git a/srcs/libs/args/argtable3.c b/srcs/libs/args/argtable3.c index 2a82e9d..0082568 100644 --- a/srcs/libs/args/argtable3.c +++ b/srcs/libs/args/argtable3.c @@ -1477,8 +1477,8 @@ static void warnx(const char *fmt, ...) { */ memset(opterrmsg, 0, sizeof(opterrmsg)); if (fmt != NULL) -#if (defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__)) \ - || (defined(__STDC_SECURE_LIB__) && defined(__STDC_WANT_SECURE_LIB__)) +#if (defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__)) || \ + (defined(__STDC_SECURE_LIB__) && defined(__STDC_WANT_SECURE_LIB__)) _vsnprintf_s(opterrmsg, sizeof(opterrmsg), sizeof(opterrmsg) - 1, fmt, ap); #else _vsnprintf(opterrmsg, sizeof(opterrmsg) - 1, fmt, ap); @@ -1617,9 +1617,8 @@ static int parse_long_options(char *const *nargv, if (match == -1) { /* first partial match */ match = i; - } else if ((flags & FLAG_LONGONLY) || long_options[i].has_arg != long_options[match].has_arg - || long_options[i].flag != long_options[match].flag - || long_options[i].val != long_options[match].val) { + } else if ((flags & FLAG_LONGONLY) || long_options[i].has_arg != long_options[match].has_arg || + long_options[i].flag != long_options[match].flag || long_options[i].val != long_options[match].val) { second_partial_match = 1; } } @@ -1750,9 +1749,9 @@ static int getopt_internal(int nargc, * string begins with a '+'. */ if (posixly_correct == -1 || optreset) { -#if defined(_WIN32) \ - && ((defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__)) \ - || (defined(__STDC_SECURE_LIB__) && defined(__STDC_WANT_SECURE_LIB__))) +#if defined(_WIN32) && \ + ((defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__)) || \ + (defined(__STDC_SECURE_LIB__) && defined(__STDC_WANT_SECURE_LIB__))) size_t requiredSize; getenv_s(&requiredSize, NULL, 0, "POSIXLY_CORRECT"); posixly_correct = requiredSize != 0; @@ -1880,8 +1879,8 @@ start: } } - if ((optchar = (int)*place++) == (int)':' || (optchar == (int)'-' && *place != '\0') - || (oli = strchr(options, optchar)) == NULL) { + if ((optchar = (int)*place++) == (int)':' || (optchar == (int)'-' && *place != '\0') || + (oli = strchr(options, optchar)) == NULL) { /* * If the user specified "-" and '-' isn't listed in * options, return -1 (non-option) as per POSIX. @@ -2765,8 +2764,8 @@ struct arg_dbl *arg_dbln(const char *shortopts, maxcount = (maxcount < mincount) ? mincount : maxcount; nbytes = sizeof(struct arg_dbl) /* storage for struct arg_dbl */ - + (size_t)(maxcount + 1) - * sizeof(double); /* storage for dval[maxcount] array plus one extra for padding to memory boundary */ + + (size_t)(maxcount + 1) * + sizeof(double); /* storage for dval[maxcount] array plus one extra for padding to memory boundary */ result = (struct arg_dbl *)xmalloc(nbytes); @@ -4343,8 +4342,8 @@ static int trex_element(TRex *exp) { ret = nnode; } } - if ((*exp->_p != TREX_SYMBOL_BRANCH) && (*exp->_p != ')') && (*exp->_p != TREX_SYMBOL_GREEDY_ZERO_OR_MORE) - && (*exp->_p != TREX_SYMBOL_GREEDY_ONE_OR_MORE) && (*exp->_p != '\0')) { + if ((*exp->_p != TREX_SYMBOL_BRANCH) && (*exp->_p != ')') && (*exp->_p != TREX_SYMBOL_GREEDY_ZERO_OR_MORE) && + (*exp->_p != TREX_SYMBOL_GREEDY_ONE_OR_MORE) && (*exp->_p != '\0')) { int nnode = trex_element(exp); exp->_nodes[ret].next = nnode; } @@ -4477,8 +4476,8 @@ static const TRexChar *trex_matchnode(TRex *exp, TRexNode *node, const TRexChar if (greedystop) { /* checks that 0 matches satisfy the expression(if so skips) */ /* if not would always stop(for instance if is a '?') */ - if (greedystop->type != OP_GREEDY - || (greedystop->type == OP_GREEDY && ((greedystop->right >> 16) & 0x0000FFFF) != 0)) { + if (greedystop->type != OP_GREEDY || + (greedystop->type == OP_GREEDY && ((greedystop->right >> 16) & 0x0000FFFF) != 0)) { TRexNode *gnext = NULL; if (greedystop->next != -1) { gnext = &exp->_nodes[greedystop->next]; @@ -4567,9 +4566,9 @@ static const TRexChar *trex_matchnode(TRex *exp, TRexNode *node, const TRexChar return cur; } case OP_WB: - if ((str == exp->_bol && !isspace((int)(*str))) || (str == exp->_eol && !isspace((int)(*(str - 1)))) - || (!isspace((int)(*str)) && isspace((int)(*(str + 1)))) - || (isspace((int)(*str)) && !isspace((int)(*(str + 1))))) { + if ((str == exp->_bol && !isspace((int)(*str))) || (str == exp->_eol && !isspace((int)(*(str - 1)))) || + (!isspace((int)(*str)) && isspace((int)(*(str + 1)))) || + (isspace((int)(*str)) && !isspace((int)(*(str + 1))))) { return (node->left == 'b') ? str : NULL; } return (node->left == 'b') ? NULL : str; @@ -4956,8 +4955,8 @@ void arg_set_module_name(const char *name) { s_module_name = (char *)xmalloc(slen + 1); memset(s_module_name, 0, slen + 1); -#if (defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__)) \ - || (defined(__STDC_SECURE_LIB__) && defined(__STDC_WANT_SECURE_LIB__)) +#if (defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__)) || \ + (defined(__STDC_SECURE_LIB__) && defined(__STDC_WANT_SECURE_LIB__)) strncpy_s(s_module_name, slen + 1, name, slen); #else memcpy(s_module_name, name, slen); @@ -4977,8 +4976,8 @@ void arg_set_module_version(int major, int minor, int patch, const char *tag) { s_mod_ver_tag = (char *)xmalloc(slen_tag + 1); memset(s_mod_ver_tag, 0, slen_tag + 1); -#if (defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__)) \ - || (defined(__STDC_SECURE_LIB__) && defined(__STDC_WANT_SECURE_LIB__)) +#if (defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__)) || \ + (defined(__STDC_SECURE_LIB__) && defined(__STDC_WANT_SECURE_LIB__)) strncpy_s(s_mod_ver_tag, slen_tag + 1, tag, slen_tag); #else memcpy(s_mod_ver_tag, tag, slen_tag); @@ -4995,8 +4994,8 @@ void arg_set_module_version(int major, int minor, int patch, const char *tag) { s_mod_ver = (char *)xmalloc(slen_ds + 1); memset(s_mod_ver, 0, slen_ds + 1); -#if (defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__)) \ - || (defined(__STDC_SECURE_LIB__) && defined(__STDC_WANT_SECURE_LIB__)) +#if (defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__)) || \ + (defined(__STDC_SECURE_LIB__) && defined(__STDC_WANT_SECURE_LIB__)) strncpy_s(s_mod_ver, slen_ds + 1, arg_dstr_cstr(ds), slen_ds); #else memcpy(s_mod_ver, arg_dstr_cstr(ds), slen_ds); @@ -5051,8 +5050,8 @@ void arg_cmd_register(const char *name, arg_cmdfn *proc, const char *description cmd_info = (arg_cmd_info_t *)xmalloc(sizeof(arg_cmd_info_t)); memset(cmd_info, 0, sizeof(arg_cmd_info_t)); -#if (defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__)) \ - || (defined(__STDC_SECURE_LIB__) && defined(__STDC_WANT_SECURE_LIB__)) +#if (defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__)) || \ + (defined(__STDC_SECURE_LIB__) && defined(__STDC_WANT_SECURE_LIB__)) strncpy_s(cmd_info->name, ARG_CMD_NAME_LEN, name, strlen(name)); strncpy_s(cmd_info->description, ARG_CMD_DESCRIPTION_LEN, description, strlen(description)); #else @@ -5066,8 +5065,8 @@ void arg_cmd_register(const char *name, arg_cmdfn *proc, const char *description k = xmalloc(slen_name + 1); memset(k, 0, slen_name + 1); -#if (defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__)) \ - || (defined(__STDC_SECURE_LIB__) && defined(__STDC_WANT_SECURE_LIB__)) +#if (defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__)) || \ + (defined(__STDC_SECURE_LIB__) && defined(__STDC_WANT_SECURE_LIB__)) strncpy_s((char *)k, slen_name + 1, name, slen_name); #else memcpy((char *)k, name, slen_name); @@ -5760,8 +5759,8 @@ static void arg_cat_option(char *dest, /* add comma separated option tag */ ncspn = strcspn(longopts, ","); -#if (defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__)) \ - || (defined(__STDC_SECURE_LIB__) && defined(__STDC_WANT_SECURE_LIB__)) +#if (defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__)) || \ + (defined(__STDC_SECURE_LIB__) && defined(__STDC_WANT_SECURE_LIB__)) strncat_s(dest, ndest, longopts, (ncspn < ndest) ? ncspn : ndest); #else strncat(dest, longopts, (ncspn < ndest) ? ncspn : ndest); @@ -5831,8 +5830,8 @@ static void arg_cat_optionv(char *dest, /* add comma separated option tag */ ncspn = strcspn(c, ","); -#if (defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__)) \ - || (defined(__STDC_SECURE_LIB__) && defined(__STDC_WANT_SECURE_LIB__)) +#if (defined(__STDC_LIB_EXT1__) && defined(__STDC_WANT_LIB_EXT1__)) || \ + (defined(__STDC_SECURE_LIB__) && defined(__STDC_WANT_SECURE_LIB__)) strncat_s(dest, ndest, c, (ncspn < ndest) ? ncspn : ndest); #else strncat(dest, c, (ncspn < ndest) ? ncspn : ndest); @@ -5978,8 +5977,12 @@ void arg_print_syntax_ds(arg_dstr_t ds, void **argtable, const char *suffix) { shortopts = table[tabindex]->shortopts; longopts = table[tabindex]->longopts; datatype = table[tabindex]->datatype; - arg_cat_option( - syntax, sizeof(syntax) - 1, shortopts, longopts, datatype, table[tabindex]->flag & ARG_HASOPTVALUE); + arg_cat_option(syntax, + sizeof(syntax) - 1, + shortopts, + longopts, + datatype, + table[tabindex]->flag & ARG_HASOPTVALUE); if (strlen(syntax) > 0) { /* print mandatory instances of this option */ @@ -6038,8 +6041,13 @@ void arg_print_syntaxv_ds(arg_dstr_t ds, void **argtable, const char *suffix) { shortopts = table[tabindex]->shortopts; longopts = table[tabindex]->longopts; datatype = table[tabindex]->datatype; - arg_cat_optionv( - syntax, sizeof(syntax) - 1, shortopts, longopts, datatype, table[tabindex]->flag & ARG_HASOPTVALUE, "|"); + arg_cat_optionv(syntax, + sizeof(syntax) - 1, + shortopts, + longopts, + datatype, + table[tabindex]->flag & ARG_HASOPTVALUE, + "|"); /* print mandatory options */ for (i = 0; i < table[tabindex]->mincount; i++) { diff --git a/srcs/libs/cmdline/cmd_menu.c b/srcs/libs/cmdline/cmd_menu.c index efd65fa..275377d 100644 --- a/srcs/libs/cmdline/cmd_menu.c +++ b/srcs/libs/cmdline/cmd_menu.c @@ -343,8 +343,8 @@ static int on_cmd6(void *pTbl[], const char *pName, void *pInfo) { return ERR_MENU_EXIT; } - if (symmetric_encrypto(DES3_CBC_PKCS7PADDING, (unsigned char *)pKey, strlen(pKey), &buf, &outSize, pKeygen) - != ERR_SUCCESS) { + if (symmetric_encrypto(DES3_CBC_PKCS7PADDING, (unsigned char *)pKey, strlen(pKey), &buf, &outSize, pKeygen) != + ERR_SUCCESS) { free((void *)pKeygen); return -ERR_EVP_ENCRYPTION; } else { diff --git a/srcs/libs/configure/config.c b/srcs/libs/configure/config.c index 9a5458a..26b01a5 100644 --- a/srcs/libs/configure/config.c +++ b/srcs/libs/configure/config.c @@ -151,8 +151,8 @@ static const char *load_string_value(const char *pKeyName) { return NULL; } - if (symmetric_decrypto(AES128_ECB_PKCS7PADDING_SHA1PRNG, pBuf, bufSize, &buf, &outSize, pKey) - != ERR_SUCCESS) { + if (symmetric_decrypto(AES128_ECB_PKCS7PADDING_SHA1PRNG, pBuf, bufSize, &buf, &outSize, pKey) != + ERR_SUCCESS) { free((void *)pKey); free(pBuf); return NULL; @@ -230,9 +230,8 @@ static int cmp_dhcp_obj(const void *a, const void *b) { POBJ_DHCP_RNG pV1 = (POBJ_DHCP_RNG)a; POBJ_DHCP_RNG pV2 = (POBJ_DHCP_RNG)b; - if (strcmp(pV1->rangAddr, pV2->rangAddr) == 0 && strcmp(pV1->subnet, pV2->subnet) == 0 - && strcmp(pV1->dnsSvr, pV2->dnsSvr) == 0 && strcmp(pV1->gateway, pV2->gateway) == 0 - && pV1->lease == pV2->lease) { + if (strcmp(pV1->rangAddr, pV2->rangAddr) == 0 && strcmp(pV1->subnet, pV2->subnet) == 0 && + strcmp(pV1->dnsSvr, pV2->dnsSvr) == 0 && strcmp(pV1->gateway, pV2->gateway) == 0 && pV1->lease == pV2->lease) { return 0; } @@ -512,8 +511,12 @@ const char *config_item_dump_fmt(const char *titleMessage) { CFG_BOOL_VALUE(pItem) ? "True" : "False"); break; case VAL_INT: - s = sdscatprintf( - s, "|%4d | %-25s | %-45s | %-64lld |\n", pItem->cfgId, tmp2, pItem->pcfgKey, CFG_INT_VALUE(pItem)); + s = sdscatprintf(s, + "|%4d | %-25s | %-45s | %-64lld |\n", + pItem->cfgId, + tmp2, + pItem->pcfgKey, + CFG_INT_VALUE(pItem)); break; case VAL_FLOAT: s = sdscatprintf(s, diff --git a/srcs/libs/include/s2j/s2jdef.h b/srcs/libs/include/s2j/s2jdef.h index 8f1f958..a8532f8 100644 --- a/srcs/libs/include/s2j/s2jdef.h +++ b/srcs/libs/include/s2j/s2jdef.h @@ -220,14 +220,22 @@ typedef struct { for (; index_##_element < realsize_##_element && index_##_element < size; index_##_element++) { \ array_item_##_element = cJSON_GetArrayItem(array_##_element, index_##_element); \ if (array_item_##_element) { \ - S2J_STRUCT_ARRAY_GET_ELEMENT_EX( \ - to_struct, array_item_##_element, type, _element, index_##_element, _defval); \ + S2J_STRUCT_ARRAY_GET_ELEMENT_EX(to_struct, \ + array_item_##_element, \ + type, \ + _element, \ + index_##_element, \ + _defval); \ } \ } \ } else { \ for (; index_##_element < realsize_##_element && index_##_element < size; index_##_element++) { \ - S2J_STRUCT_ARRAY_GET_ELEMENT_EX( \ - to_struct, array_##_element, type, _element, index_##_element, _defval); \ + S2J_STRUCT_ARRAY_GET_ELEMENT_EX(to_struct, \ + array_##_element, \ + type, \ + _element, \ + index_##_element, \ + _defval); \ } \ } \ } else { \ diff --git a/srcs/libs/include/uthash/utarray.h b/srcs/libs/include/uthash/utarray.h index 9730464..2919a07 100644 --- a/srcs/libs/include/uthash/utarray.h +++ b/srcs/libs/include/uthash/utarray.h @@ -212,19 +212,20 @@ typedef struct { utarray_inserta(dst, src, utarray_len(dst)); \ } while (0) -#define utarray_erase(a, pos, len) \ - do { \ - if ((a)->icd.dtor) { \ - unsigned _ut_i; \ - for (_ut_i = 0; _ut_i < (len); _ut_i++) { \ - (a)->icd.dtor(utarray_eltptr(a, (pos) + _ut_i)); \ - } \ - } \ - if ((a)->i > ((pos) + (len))) { \ - memmove( \ - _utarray_eltptr(a, pos), _utarray_eltptr(a, (pos) + (len)), ((a)->i - ((pos) + (len))) * (a)->icd.sz); \ - } \ - (a)->i -= (len); \ +#define utarray_erase(a, pos, len) \ + do { \ + if ((a)->icd.dtor) { \ + unsigned _ut_i; \ + for (_ut_i = 0; _ut_i < (len); _ut_i++) { \ + (a)->icd.dtor(utarray_eltptr(a, (pos) + _ut_i)); \ + } \ + } \ + if ((a)->i > ((pos) + (len))) { \ + memmove(_utarray_eltptr(a, pos), \ + _utarray_eltptr(a, (pos) + (len)), \ + ((a)->i - ((pos) + (len))) * (a)->icd.sz); \ + } \ + (a)->i -= (len); \ } while (0) #define utarray_renew(a, u) \ diff --git a/srcs/libs/include/uthash/uthash.h b/srcs/libs/include/uthash/uthash.h index 1328cdc..a93311d 100644 --- a/srcs/libs/include/uthash/uthash.h +++ b/srcs/libs/include/uthash/uthash.h @@ -226,8 +226,8 @@ typedef unsigned char uint8_t; (head)->hh.tbl->num_buckets = HASH_INITIAL_NUM_BUCKETS; \ (head)->hh.tbl->log2_num_buckets = HASH_INITIAL_NUM_BUCKETS_LOG2; \ (head)->hh.tbl->hho = (char *)(&(head)->hh) - (char *)(head); \ - (head)->hh.tbl->buckets = (UT_hash_bucket *)uthash_malloc(HASH_INITIAL_NUM_BUCKETS \ - * sizeof(struct UT_hash_bucket)); \ + (head)->hh.tbl->buckets = (UT_hash_bucket *)uthash_malloc(HASH_INITIAL_NUM_BUCKETS * \ + sizeof(struct UT_hash_bucket)); \ (head)->hh.tbl->signature = HASH_SIGNATURE; \ if (!(head)->hh.tbl->buckets) { \ HASH_RECORD_OOM(oomed); \ @@ -523,8 +523,10 @@ typedef unsigned char uint8_t; _prev = NULL; \ while (_thh) { \ if (_prev != (char *)(_thh->hh_prev)) { \ - HASH_OOPS( \ - "%s: invalid hh_prev %p, actual %p\n", (where), (void *)_thh->hh_prev, (void *)_prev); \ + HASH_OOPS("%s: invalid hh_prev %p, actual %p\n", \ + (where), \ + (void *)_thh->hh_prev, \ + (void *)_prev); \ } \ _bkt_count++; \ _prev = (char *)(_thh); \ @@ -655,59 +657,59 @@ typedef unsigned char uint8_t; c ^= (b >> 15); \ } while (0) -#define HASH_JEN(key, keylen, hashv) \ - do { \ - unsigned _hj_i, _hj_j, _hj_k; \ - unsigned const char *_hj_key = (unsigned const char *)(key); \ - hashv = 0xfeedbeefu; \ - _hj_i = _hj_j = 0x9e3779b9u; \ - _hj_k = (unsigned)(keylen); \ - while (_hj_k >= 12U) { \ - _hj_i += (_hj_key[0] + ((unsigned)_hj_key[1] << 8) + ((unsigned)_hj_key[2] << 16) \ - + ((unsigned)_hj_key[3] << 24)); \ - _hj_j += (_hj_key[4] + ((unsigned)_hj_key[5] << 8) + ((unsigned)_hj_key[6] << 16) \ - + ((unsigned)_hj_key[7] << 24)); \ - hashv += (_hj_key[8] + ((unsigned)_hj_key[9] << 8) + ((unsigned)_hj_key[10] << 16) \ - + ((unsigned)_hj_key[11] << 24)); \ - \ - HASH_JEN_MIX(_hj_i, _hj_j, hashv); \ - \ - _hj_key += 12; \ - _hj_k -= 12U; \ - } \ - hashv += (unsigned)(keylen); \ - switch (_hj_k) { \ - case 11: \ - hashv += ((unsigned)_hj_key[10] << 24); /* FALLTHROUGH */ \ - case 10: \ - hashv += ((unsigned)_hj_key[9] << 16); /* FALLTHROUGH */ \ - case 9: \ - hashv += ((unsigned)_hj_key[8] << 8); /* FALLTHROUGH */ \ - case 8: \ - _hj_j += ((unsigned)_hj_key[7] << 24); /* FALLTHROUGH */ \ - case 7: \ - _hj_j += ((unsigned)_hj_key[6] << 16); /* FALLTHROUGH */ \ - case 6: \ - _hj_j += ((unsigned)_hj_key[5] << 8); /* FALLTHROUGH */ \ - case 5: \ - _hj_j += _hj_key[4]; /* FALLTHROUGH */ \ - case 4: \ - _hj_i += ((unsigned)_hj_key[3] << 24); /* FALLTHROUGH */ \ - case 3: \ - _hj_i += ((unsigned)_hj_key[2] << 16); /* FALLTHROUGH */ \ - case 2: \ - _hj_i += ((unsigned)_hj_key[1] << 8); /* FALLTHROUGH */ \ - case 1: \ - _hj_i += _hj_key[0]; /* FALLTHROUGH */ \ - default:; \ - } \ - HASH_JEN_MIX(_hj_i, _hj_j, hashv); \ +#define HASH_JEN(key, keylen, hashv) \ + do { \ + unsigned _hj_i, _hj_j, _hj_k; \ + unsigned const char *_hj_key = (unsigned const char *)(key); \ + hashv = 0xfeedbeefu; \ + _hj_i = _hj_j = 0x9e3779b9u; \ + _hj_k = (unsigned)(keylen); \ + while (_hj_k >= 12U) { \ + _hj_i += (_hj_key[0] + ((unsigned)_hj_key[1] << 8) + ((unsigned)_hj_key[2] << 16) + \ + ((unsigned)_hj_key[3] << 24)); \ + _hj_j += (_hj_key[4] + ((unsigned)_hj_key[5] << 8) + ((unsigned)_hj_key[6] << 16) + \ + ((unsigned)_hj_key[7] << 24)); \ + hashv += (_hj_key[8] + ((unsigned)_hj_key[9] << 8) + ((unsigned)_hj_key[10] << 16) + \ + ((unsigned)_hj_key[11] << 24)); \ + \ + HASH_JEN_MIX(_hj_i, _hj_j, hashv); \ + \ + _hj_key += 12; \ + _hj_k -= 12U; \ + } \ + hashv += (unsigned)(keylen); \ + switch (_hj_k) { \ + case 11: \ + hashv += ((unsigned)_hj_key[10] << 24); /* FALLTHROUGH */ \ + case 10: \ + hashv += ((unsigned)_hj_key[9] << 16); /* FALLTHROUGH */ \ + case 9: \ + hashv += ((unsigned)_hj_key[8] << 8); /* FALLTHROUGH */ \ + case 8: \ + _hj_j += ((unsigned)_hj_key[7] << 24); /* FALLTHROUGH */ \ + case 7: \ + _hj_j += ((unsigned)_hj_key[6] << 16); /* FALLTHROUGH */ \ + case 6: \ + _hj_j += ((unsigned)_hj_key[5] << 8); /* FALLTHROUGH */ \ + case 5: \ + _hj_j += _hj_key[4]; /* FALLTHROUGH */ \ + case 4: \ + _hj_i += ((unsigned)_hj_key[3] << 24); /* FALLTHROUGH */ \ + case 3: \ + _hj_i += ((unsigned)_hj_key[2] << 16); /* FALLTHROUGH */ \ + case 2: \ + _hj_i += ((unsigned)_hj_key[1] << 8); /* FALLTHROUGH */ \ + case 1: \ + _hj_i += _hj_key[0]; /* FALLTHROUGH */ \ + default:; \ + } \ + HASH_JEN_MIX(_hj_i, _hj_j, hashv); \ } while (0) /* The Paul Hsieh hash function */ #undef get16bits -#if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) || defined(_MSC_VER) || defined(__BORLANDC__) \ - || defined(__TURBOC__) +#if (defined(__GNUC__) && defined(__i386__)) || defined(__WATCOMC__) || defined(_MSC_VER) || defined(__BORLANDC__) || \ + defined(__TURBOC__) #define get16bits(d) (*((const uint16_t *)(d))) #endif @@ -785,21 +787,21 @@ typedef unsigned char uint8_t; } while (0) /* add an item to a bucket */ -#define HASH_ADD_TO_BKT(head, hh, addhh, oomed) \ - do { \ - UT_hash_bucket *_ha_head = &(head); \ - _ha_head->count++; \ - (addhh)->hh_next = _ha_head->hh_head; \ - (addhh)->hh_prev = NULL; \ - if (_ha_head->hh_head != NULL) { \ - _ha_head->hh_head->hh_prev = (addhh); \ - } \ - _ha_head->hh_head = (addhh); \ - if ((_ha_head->count >= ((_ha_head->expand_mult + 1U) * HASH_BKT_CAPACITY_THRESH)) \ - && !(addhh)->tbl->noexpand) { \ - HASH_EXPAND_BUCKETS(addhh, (addhh)->tbl, oomed); \ - IF_HASH_NONFATAL_OOM(if (oomed) { HASH_DEL_IN_BKT(head, addhh); }) \ - } \ +#define HASH_ADD_TO_BKT(head, hh, addhh, oomed) \ + do { \ + UT_hash_bucket *_ha_head = &(head); \ + _ha_head->count++; \ + (addhh)->hh_next = _ha_head->hh_head; \ + (addhh)->hh_prev = NULL; \ + if (_ha_head->hh_head != NULL) { \ + _ha_head->hh_head->hh_prev = (addhh); \ + } \ + _ha_head->hh_head = (addhh); \ + if ((_ha_head->count >= ((_ha_head->expand_mult + 1U) * HASH_BKT_CAPACITY_THRESH)) && \ + !(addhh)->tbl->noexpand) { \ + HASH_EXPAND_BUCKETS(addhh, (addhh)->tbl, oomed); \ + IF_HASH_NONFATAL_OOM(if (oomed) { HASH_DEL_IN_BKT(head, addhh); }) \ + } \ } while (0) /* remove an item from a given bucket */ @@ -858,8 +860,8 @@ typedef unsigned char uint8_t; HASH_RECORD_OOM(oomed); \ } else { \ uthash_bzero(_he_new_buckets, sizeof(struct UT_hash_bucket) * (tbl)->num_buckets * 2U); \ - (tbl)->ideal_chain_maxlen = ((tbl)->num_items >> ((tbl)->log2_num_buckets + 1U)) \ - + ((((tbl)->num_items & (((tbl)->num_buckets * 2U) - 1U)) != 0U) ? 1U : 0U); \ + (tbl)->ideal_chain_maxlen = ((tbl)->num_items >> ((tbl)->log2_num_buckets + 1U)) + \ + ((((tbl)->num_items & (((tbl)->num_buckets * 2U) - 1U)) != 0U) ? 1U : 0U); \ (tbl)->nonideal_items = 0; \ for (_he_bkt_i = 0; _he_bkt_i < (tbl)->num_buckets; _he_bkt_i++) { \ _he_thh = (tbl)->buckets[_he_bkt_i].hh_head; \ @@ -938,8 +940,7 @@ typedef unsigned char uint8_t; } \ _hs_psize--; \ } else if ((cmpfcn(DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl, _hs_p)), \ - DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl, _hs_q)))) \ - <= 0) { \ + DECLTYPE(head)(ELMT_FROM_HH((head)->hh.tbl, _hs_q)))) <= 0) { \ _hs_e = _hs_p; \ if (_hs_p != NULL) { \ _hs_p = ((_hs_p->next != NULL) ? HH_FROM_ELMT((head)->hh.tbl, _hs_p->next) : NULL); \ @@ -1045,9 +1046,9 @@ typedef unsigned char uint8_t; } while (0) #define HASH_OVERHEAD(hh, head) \ - (((head) != NULL) ? ((size_t)(((head)->hh.tbl->num_items * sizeof(UT_hash_handle)) \ - + ((head)->hh.tbl->num_buckets * sizeof(UT_hash_bucket)) + sizeof(UT_hash_table) \ - + (HASH_BLOOM_BYTELEN))) \ + (((head) != NULL) ? ((size_t)(((head)->hh.tbl->num_items * sizeof(UT_hash_handle)) + \ + ((head)->hh.tbl->num_buckets * sizeof(UT_hash_bucket)) + sizeof(UT_hash_table) + \ + (HASH_BLOOM_BYTELEN))) \ : 0U) #ifdef NO_DECLTYPE diff --git a/srcs/libs/include/zvector/zvector_checks.h b/srcs/libs/include/zvector/zvector_checks.h index 4c8a25d..6810955 100644 --- a/srcs/libs/include/zvector/zvector_checks.h +++ b/srcs/libs/include/zvector/zvector_checks.h @@ -107,8 +107,8 @@ #elif defined(__aarch32__) #define CPU_TYPE ARM32 #define Arch32 -#elif defined(__amd64__) || defined(__x86_64__) || defined(__ia64__) || defined(_M_IA64) || defined(_M_AMD64) \ - || defined(_M_X64) +#elif defined(__amd64__) || defined(__x86_64__) || defined(__ia64__) || defined(_M_IA64) || defined(_M_AMD64) || \ + defined(_M_X64) #define CPU_TYPE x86_64 #define Arch64 #else diff --git a/srcs/libs/json/cJSON.c b/srcs/libs/json/cJSON.c index 28d515c..34d1930 100644 --- a/srcs/libs/json/cJSON.c +++ b/srcs/libs/json/cJSON.c @@ -939,7 +939,11 @@ cJSON_ParseWithLengthOpts(const char *value, const char **return_parse_end, cJSON_bool require_null_terminated) { parse_buffer buffer = { - 0, 0, 0, 0, {0, 0, 0} + 0, + 0, + 0, + 0, + {0, 0, 0} }; cJSON *item = NULL; @@ -1084,7 +1088,13 @@ CJSON_PUBLIC(char *) cJSON_PrintUnformatted(const cJSON *item) { CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON_bool fmt) { printbuffer p = { - 0, 0, 0, 0, 0, 0, {0, 0, 0} + 0, + 0, + 0, + 0, + 0, + 0, + {0, 0, 0} }; if (prebuffer < 0) { @@ -1112,7 +1122,13 @@ CJSON_PUBLIC(char *) cJSON_PrintBuffered(const cJSON *item, int prebuffer, cJSON CJSON_PUBLIC(cJSON_bool) cJSON_PrintPreallocated(cJSON *item, char *buffer, const int length, const cJSON_bool format) { printbuffer p = { - 0, 0, 0, 0, 0, 0, {0, 0, 0} + 0, + 0, + 0, + 0, + 0, + 0, + {0, 0, 0} }; if ((length < 0) || (buffer == NULL)) { @@ -1160,9 +1176,9 @@ static cJSON_bool parse_value(cJSON *const item, parse_buffer *const input_buffe return parse_string(item, input_buffer); } /* number */ - if (can_access_at_index(input_buffer, 0) - && ((buffer_at_offset(input_buffer)[0] == '-') - || ((buffer_at_offset(input_buffer)[0] >= '0') && (buffer_at_offset(input_buffer)[0] <= '9')))) { + if (can_access_at_index(input_buffer, 0) && + ((buffer_at_offset(input_buffer)[0] == '-') || + ((buffer_at_offset(input_buffer)[0] >= '0') && (buffer_at_offset(input_buffer)[0] <= '9')))) { return parse_number(item, input_buffer); } /* array */ @@ -1626,15 +1642,14 @@ static cJSON *get_object_item(const cJSON *const object, const char *const name, current_element = object->child; if (case_sensitive) { - while ((current_element != NULL) && (current_element->string != NULL) - && (strcmp(name, current_element->string) != 0)) { + while ((current_element != NULL) && (current_element->string != NULL) && + (strcmp(name, current_element->string) != 0)) { current_element = current_element->next; } } else { - while ( - (current_element != NULL) - && (case_insensitive_strcmp((const unsigned char *)name, (const unsigned char *)(current_element->string)) - != 0)) { + while ((current_element != NULL) && + (case_insensitive_strcmp((const unsigned char *)name, + (const unsigned char *)(current_element->string)) != 0)) { current_element = current_element->next; } } diff --git a/srcs/libs/misc/sds.c b/srcs/libs/misc/sds.c index d3d9ace..b15cfdc 100644 --- a/srcs/libs/misc/sds.c +++ b/srcs/libs/misc/sds.c @@ -389,8 +389,8 @@ void sdsIncrLen(sds s, int incr) { } case SDS_TYPE_32: { SDS_HDR_VAR(32, s); - assert((incr >= 0 && sh->alloc - sh->len >= (unsigned int)incr) - || (incr < 0 && sh->len >= (unsigned int)(-incr))); + assert((incr >= 0 && sh->alloc - sh->len >= (unsigned int)incr) || + (incr < 0 && sh->len >= (unsigned int)(-incr))); len = (sh->len += incr); break; } @@ -1331,12 +1331,11 @@ int sdsTest(void) { x = sdsnew("--"); x = sdscatfmt(x, "Hello %s World %I,%I--", "Hi!", LLONG_MIN, LLONG_MAX); test_cond("sdscatfmt() seems working in the base case", - sdslen(x) == 60 - && memcmp(x, - "--Hello Hi! World -9223372036854775808," - "9223372036854775807--", - 60) - == 0) printf("[%s]\n", x); + sdslen(x) == 60 && + memcmp(x, + "--Hello Hi! World -9223372036854775808," + "9223372036854775807--", + 60) == 0) printf("[%s]\n", x); sdsfree(x); x = sdsnew("--"); @@ -1444,8 +1443,7 @@ int sdsTest(void) { memcmp("0ABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGHIJABCDEFGH" "IJABCDEFGHIJ", x, - 101) - == 0); + 101) == 0); test_cond("sdsMakeRoomFor() final length", sdslen(x) == 101); sdsfree(x); diff --git a/srcs/libs/misc/zvector.c b/srcs/libs/misc/zvector.c index be5c3e6..405ce45 100644 --- a/srcs/libs/misc/zvector.c +++ b/srcs/libs/misc/zvector.c @@ -307,7 +307,8 @@ p_throw_error(const zvect_retval error_code, const char *error_message) { break; case ZVERR_VECTDATASIZE: message = (char *)safe_strncpy( - "This operation requires two (or more vectors) with the same data size.\n\0", msg_len); + "This operation requires two (or more vectors) with the same data size.\n\0", + msg_len); break; case ZVERR_VECTEMPTY: message = (char *)safe_strncpy("Vector is empty.\n\0", msg_len); @@ -351,8 +352,8 @@ static inline // Using improved memcpy (where improved means for // embedded systems only!): if (size > 0) { - if (((uintptr_t)dst % sizeof(ADDR_TYPE1) == 0) && ((uintptr_t)src % sizeof(ADDR_TYPE1) == 0) - && (size % sizeof(ADDR_TYPE1) == 0)) { + if (((uintptr_t)dst % sizeof(ADDR_TYPE1) == 0) && ((uintptr_t)src % sizeof(ADDR_TYPE1) == 0) && + (size % sizeof(ADDR_TYPE1) == 0)) { ADDR_TYPE1 *pExDst = (ADDR_TYPE1 *)dst; ADDR_TYPE1 const *pExSrc = (ADDR_TYPE1 const *)src; size_t end = size / sizeof(ADDR_TYPE1); @@ -2887,8 +2888,9 @@ void vect_insert(vector const v1, vector const v2, const zvect_index s2, const z const void *rptr = NULL; // Reserve appropriate space in the destination vector - rptr = p_vect_memmove( - v1->data + (v1->begin + s1 + ee2), v1->data + (v1->begin + s1), sizeof(void *) * (p_vect_size(v1) - s1)); + rptr = p_vect_memmove(v1->data + (v1->begin + s1 + ee2), + v1->data + (v1->begin + s1), + sizeof(void *) * (p_vect_size(v1) - s1)); if (rptr == NULL) { rval = ZVERR_VECTCORRUPTED; @@ -3016,11 +3018,13 @@ static inline zvect_retval p_vect_move(vector const v1, vector v2, const zvect_i // Move v2 (from s2) in v1 at the end of v1: const void *rptr = NULL; if (v1 != v2) { - rptr = p_vect_memcpy( - v1->data + (v1->begin + p_vect_size(v1)), v2->data + (v2->begin + s2), sizeof(void *) * ee2); + rptr = p_vect_memcpy(v1->data + (v1->begin + p_vect_size(v1)), + v2->data + (v2->begin + s2), + sizeof(void *) * ee2); } else { - rptr = p_vect_memmove( - v1->data + (v1->begin + p_vect_size(v1)), v2->data + (v2->begin + s2), sizeof(void *) * ee2); + rptr = p_vect_memmove(v1->data + (v1->begin + p_vect_size(v1)), + v2->data + (v2->begin + s2), + sizeof(void *) * ee2); } if (rptr == NULL) { diff --git a/srcs/libs/network/inet_misc.c b/srcs/libs/network/inet_misc.c index 66586ed..ff7cd4f 100644 --- a/srcs/libs/network/inet_misc.c +++ b/srcs/libs/network/inet_misc.c @@ -229,8 +229,10 @@ static void checkMultiInfo(void) { pReq->errCode = 0; } - uv_fs_fdatasync( - get_task_manager(), &pReq->uvFsDataSync, (uv_file)pReq->uvFsOpen.result, uvFsDataSyncCb); + uv_fs_fdatasync(get_task_manager(), + &pReq->uvFsDataSync, + (uv_file)pReq->uvFsOpen.result, + uvFsDataSyncCb); } else if (pReq->type == INET_HTTP_WEBSERVICE_POST) { if (pMsg->data.result != CURLE_OK) { if (pReq->onRspCb && pReq->isCancel == FALSE) { @@ -400,8 +402,13 @@ static size_t writeDataCb(void *pData, size_t size, size_t nmemb, void *pParams) pReq->uvFsBuf = uv_buf_init(pData, iMemSize); - wr = uv_fs_write( - get_task_manager(), &pReq->uvFsWrite, (uv_file)pReq->uvFsOpen.result, &pReq->uvFsBuf, 1, -1, NULL); + wr = uv_fs_write(get_task_manager(), + &pReq->uvFsWrite, + (uv_file)pReq->uvFsOpen.result, + &pReq->uvFsBuf, + 1, + -1, + NULL); if (wr > 0) { pReq->dlSize += wr; @@ -433,8 +440,10 @@ static int progressCb(void *pData, double total, double now, double UNUSED(ulTot if (pParams->onPrgCb) { if (pParams->type == INET_HTTP_DOWNLOAD_FILE) { - pParams->onPrgCb( - pParams->pReqUrl, pParams->pTaskUuid, (unsigned char)(now * 100.0 / total), pParams->pData); + pParams->onPrgCb(pParams->pReqUrl, + pParams->pTaskUuid, + (unsigned char)(now * 100.0 / total), + pParams->pData); } } @@ -608,8 +617,12 @@ const char *inet_download_file_async(const char *pURL, dzlog_debug("[%s]: File %s used temp path %s\n", pParams->pTaskUuid, pParams->sPath, pParams->sDlPath); - uv_fs_open( - get_task_manager(), &pParams->uvFsOpen, pParams->sDlPath, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR, NULL); + uv_fs_open(get_task_manager(), + &pParams->uvFsOpen, + pParams->sDlPath, + O_RDWR | O_CREAT | O_TRUNC, + S_IRUSR | S_IWUSR, + NULL); curl_easy_setopt(pCurl, CURLOPT_WRITEFUNCTION, writeDataCb); curl_easy_setopt(pCurl, CURLOPT_WRITEDATA, pParams); diff --git a/srcs/libs/protocol/protocol.c b/srcs/libs/protocol/protocol.c index 54e451b..b0ac0af 100644 --- a/srcs/libs/protocol/protocol.c +++ b/srcs/libs/protocol/protocol.c @@ -87,15 +87,10 @@ const char *proto_decode_context(const char *pString, unsigned int *pVer, unsign return NULL; } - pBase64 = (unsigned char *)base64_decode(pMsgCtx->valuestring, - (unsigned int *)&outSize); + pBase64 = (unsigned char *)base64_decode(pMsgCtx->valuestring, (unsigned int *)&outSize); - if (symmetric_decrypto(cryptoType, - pBase64, - outSize, - (unsigned char **)(&pMsgContent), - &decodeSize, - pKey) != ERR_SUCCESS) { + if (symmetric_decrypto(cryptoType, pBase64, outSize, (unsigned char **)(&pMsgContent), &decodeSize, pKey) != + ERR_SUCCESS) { free((void *)pBase64); if (pMsgContent) { free(pMsgContent); @@ -166,9 +161,7 @@ const char *proto_create_new(cJSON *pMsgCtx, int httpCode) { } if (pKey == NULL || strlen(pKey) == 0) { - dzlog_error( - "Cryptography key empty of algorithm %d, Used default algorithm BASE64\n", - cryptoType); + dzlog_error("Cryptography key empty of algorithm %d, Used default algorithm BASE64\n", cryptoType); base64 = base64_encode((unsigned char *)pStrMsg, strlen(pStrMsg)); pro.cryptoType = CRYPTO_BASE64; } else { @@ -176,16 +169,10 @@ const char *proto_create_new(cJSON *pMsgCtx, int httpCode) { unsigned char *buf; int outSize = 0; - ret = symmetric_encrypto(cryptoType, - (unsigned char *)pStrMsg, - strlen(pStrMsg), - &buf, - &outSize, - pKey); + ret = symmetric_encrypto(cryptoType, (unsigned char *)pStrMsg, strlen(pStrMsg), &buf, &outSize, pKey); if (ret != ERR_SUCCESS) { - dzlog_error("Unsupported protocol crypto : %d, Used default algorithm BASE64\n", - cryptoType); + dzlog_error("Unsupported protocol crypto : %d, Used default algorithm BASE64\n", cryptoType); base64 = base64_encode((unsigned char *)pStrMsg, strlen(pStrMsg)); pro.cryptoType = CRYPTO_BASE64; } else { @@ -198,9 +185,7 @@ const char *proto_create_new(cJSON *pMsgCtx, int httpCode) { cJSON_free(pro.msgContend); } break; default: - dzlog_error( - "Unsupported protocol crypto algorithms: %d, Used default algorithm BASE64\n", - pro.cryptoType); + dzlog_error("Unsupported protocol crypto algorithms: %d, Used default algorithm BASE64\n", pro.cryptoType); cJSON_free(pro.msgContend); cJSON_Delete(pRoot); return NULL;