This is an automated email from the ASF dual-hosted git repository. bcall pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/trafficserver.git
The following commit(s) were added to refs/heads/master by this push: new 13a27d7a45 Ran clang-tidy over tscore (#10535) 13a27d7a45 is described below commit 13a27d7a45a7330cb1b64d291216ae5ec15916a2 Author: Bryan Call <bc...@apache.org> AuthorDate: Thu Sep 28 06:15:17 2023 -0700 Ran clang-tidy over tscore (#10535) --- include/tscore/Allocator.h | 2 +- include/tscore/Arena.h | 10 +- include/tscore/BaseLogFile.h | 4 +- include/tscore/ContFlags.h | 5 +- include/tscore/Extendible.h | 4 +- include/tscore/History.h | 4 +- include/tscore/IntrusivePtr.h | 8 +- include/tscore/List.h | 83 +++++++++++------ include/tscore/MD5.h | 2 +- include/tscore/MatcherUtils.h | 3 +- include/tscore/ParseRules.h | 155 ++++++++++++++++++------------- include/tscore/Ptr.h | 3 +- include/tscore/SHA256.h | 2 +- include/tscore/SimpleTokenizer.h | 10 +- include/tscore/TextBuffer.h | 2 +- include/tscore/ink_args.h | 2 +- include/tscore/ink_hrtime.h | 22 ++--- include/tscore/ink_inet.h | 12 ++- include/tscore/ink_llqueue.h | 10 +- include/tscore/ink_memory.h | 13 ++- include/tscore/ink_platform.h | 2 +- include/tscore/ink_queue.h | 8 +- include/tscore/ink_rand.h | 2 +- include/tscore/ink_rwlock.h | 2 +- include/tscore/ink_string++.h | 2 +- include/tscore/ink_string.h | 8 +- include/tscore/ink_thread.h | 13 +-- include/tscore/signals.h | 2 +- include/tscpp/util/Histogram.h | 10 +- src/tscore/HKDF_openssl3.cc | 12 +-- src/tscore/MMH.cc | 8 +- src/tscore/Regex.cc | 2 +- src/tscore/ink_stack_trace.cc | 3 +- src/tscore/unit_tests/test_ArgParser.cc | 10 +- src/tscore/unit_tests/test_Encoding.cc | 4 +- src/tscore/unit_tests/test_Extendible.cc | 32 ++++--- src/tscore/unit_tests/test_MMH.cc | 24 ++--- src/tscore/unit_tests/test_Random.cc | 4 +- src/tscore/unit_tests/test_arena.cc | 2 +- 39 files changed, 287 insertions(+), 219 deletions(-) diff --git a/include/tscore/Allocator.h b/include/tscore/Allocator.h index 309dd57127..124bbf9fcb 100644 --- a/include/tscore/Allocator.h +++ b/include/tscore/Allocator.h @@ -327,7 +327,7 @@ public: ink_mutex_acquire(&trackerLock); std::map<void *, const void *>::iterator it = reverse_lookup.find(ptr); if (it != reverse_lookup.end()) { - tracker.increment((const void *)it->second, (int64_t)sizeof(C) * -1, nullptr); + tracker.increment(static_cast<const void *>(it->second), (int64_t)sizeof(C) * -1, nullptr); reverse_lookup.erase(it); } ink_mutex_release(&trackerLock); diff --git a/include/tscore/Arena.h b/include/tscore/Arena.h index 4db4808a3b..f206b40ad8 100644 --- a/include/tscore/Arena.h +++ b/include/tscore/Arena.h @@ -108,19 +108,19 @@ Arena::str_alloc(size_t len) tmp /= 128; } - mem = (unsigned char *)alloc(size, 1); + mem = static_cast<unsigned char *>(alloc(size, 1)); mem += (size - len - 1); p = mem - 1; tmp = len; while (tmp >= 128) { - *p-- = (unsigned char)(255 - (tmp % 128)); + *p-- = static_cast<unsigned char>(255 - (tmp % 128)); tmp /= 128; } - *p = (unsigned char)tmp; + *p = static_cast<unsigned char>(tmp); - return (char *)mem; + return reinterpret_cast<char *>(mem); } /*------------------------------------------------------------------------- @@ -132,7 +132,7 @@ Arena::str_free(char *str) unsigned char *p, *s, *e; size_t len; - e = (unsigned char *)str; + e = reinterpret_cast<unsigned char *>(str); s = e - 1; while (*s >= 128) { diff --git a/include/tscore/BaseLogFile.h b/include/tscore/BaseLogFile.h index ed325fbec6..eca920a1fd 100644 --- a/include/tscore/BaseLogFile.h +++ b/include/tscore/BaseLogFile.h @@ -47,13 +47,13 @@ 0 // change this to 1 to enable debug messages // TODO find a way to enable this from autotools -typedef enum { +enum LogLogPriorityLevel { LL_Debug = 0, // process does not die LL_Note, // process does not die LL_Warning, // process does not die LL_Error, // process does not die LL_Fatal, // causes process termination -} LogLogPriorityLevel; +}; #define log_log_trace(...) \ do { \ diff --git a/include/tscore/ContFlags.h b/include/tscore/ContFlags.h index f23822ebd8..33b7b5a23c 100644 --- a/include/tscore/ContFlags.h +++ b/include/tscore/ContFlags.h @@ -65,10 +65,11 @@ public: set_flag(enum flags flag_bit, bool value) { if (flag_bit >= 0 && flag_bit < LAST_FLAG) { - if (value) + if (value) { raw_flags |= (1 << flag_bit); - else + } else { raw_flags &= ~(1 << flag_bit); + } } } bool diff --git a/include/tscore/Extendible.h b/include/tscore/Extendible.h index 919d796fb9..8b22b50faf 100644 --- a/include/tscore/Extendible.h +++ b/include/tscore/Extendible.h @@ -368,7 +368,7 @@ namespace details bool fieldGet(const void *fld_ptr, FieldId<Derived_t, bool> const &field) { - return bool((*static_cast<const uint8_t *>(fld_ptr)) & field.desc->mask); + return static_cast<bool>((*static_cast<const uint8_t *>(fld_ptr)) & field.desc->mask); } template <typename Derived_t> @@ -611,7 +611,7 @@ Extendible<Derived_t>::initFields(uintptr_t start_ptr) ink_assert(ext_loc == 0); start_ptr = ROUNDUP(start_ptr, schema.alloc_align); // pad the previous struct, so that our fields are memaligned correctly ink_assert(start_ptr - uintptr_t(this) < UINT16_MAX); - ext_loc = uint16_t(start_ptr - uintptr_t(this)); // store the offset to be used by ext::get and ext::set + ext_loc = static_cast<uint16_t>(start_ptr - uintptr_t(this)); // store the offset to be used by ext::get and ext::set ink_assert(ext_loc > 0); schema.callConstructor(start_ptr); // construct all fields return start_ptr + schema.alloc_size; // return the end of the extendible data diff --git a/include/tscore/History.h b/include/tscore/History.h index 3a91d7adac..2e600dc08b 100644 --- a/include/tscore/History.h +++ b/include/tscore/History.h @@ -44,8 +44,8 @@ public: { int pos = history_pos++ % Count; history[pos].location = location; - history[pos].event = (unsigned short)event; - history[pos].reentrancy = (short)reentrant; + history[pos].event = static_cast<unsigned short>(event); + history[pos].reentrancy = static_cast<short>(reentrant); } void diff --git a/include/tscore/IntrusivePtr.h b/include/tscore/IntrusivePtr.h index 70cc671e39..8b8b2e054e 100644 --- a/include/tscore/IntrusivePtr.h +++ b/include/tscore/IntrusivePtr.h @@ -528,9 +528,10 @@ template <typename T> void IntrusivePtr<T>::set(T *obj) { - m_obj = obj; /* update to new object */ - if (nullptr != m_obj) /* if a real object, bump the ref count */ + m_obj = obj; /* update to new object */ + if (nullptr != m_obj) { /* if a real object, bump the ref count */ ++(m_obj->m_intrusive_pointer_reference_count); + } } template <typename T> @@ -552,8 +553,9 @@ IntrusivePtr<T>::release() auto &cp = m_obj->m_intrusive_pointer_reference_count; // If the client is using this method, they're doing something funky // so be extra careful with the reference count. - if (cp > 0) + if (cp > 0) { --cp; + } m_obj = nullptr; } return zret; diff --git a/include/tscore/List.h b/include/tscore/List.h index 57809badcd..929393dc1f 100644 --- a/include/tscore/List.h +++ b/include/tscore/List.h @@ -357,8 +357,9 @@ template <class C, class L> inline void DLL<C, L>::push(C *e) { - if (head) + if (head) { prev(head) = e; + } next(e) = head; head = e; } @@ -367,14 +368,18 @@ template <class C, class L> inline void DLL<C, L>::remove(C *e) { - if (!head) + if (!head) { return; - if (e == head) + } + if (e == head) { head = next(e); - if (prev(e)) + } + if (prev(e)) { next(prev(e)) = next(e); - if (next(e)) + } + if (next(e)) { prev(next(e)) = prev(e); + } prev(e) = nullptr; next(e) = nullptr; } @@ -386,12 +391,14 @@ DLL<C, L>::pop() C *ret = head; if (ret) { head = next(ret); - if (head) + if (head) { prev(head) = nullptr; + } next(ret) = nullptr; return ret; - } else + } else { return nullptr; + } } template <class C, class L> @@ -405,8 +412,9 @@ DLL<C, L>::insert(C *e, C *after) prev(e) = after; next(e) = next(after); next(after) = e; - if (next(e)) + if (next(e)) { prev(next(e)) = e; + } } template <class C, class L> @@ -566,8 +574,9 @@ inline void Queue<C, L>::push(C *e) { DLL<C, L>::push(e); - if (!tail) + if (!tail) { tail = head; + } } template <class C, class L> @@ -575,8 +584,9 @@ inline C * Queue<C, L>::pop() { C *ret = DLL<C, L>::pop(); - if (!head) + if (!head) { tail = nullptr; + } return ret; } @@ -585,18 +595,20 @@ inline void Queue<C, L>::insert(C *e, C *after) { DLL<C, L>::insert(e, after); - if (!tail) + if (!tail) { tail = head; - else if (tail == after) + } else if (tail == after) { tail = e; + } } template <class C, class L> inline void Queue<C, L>::remove(C *e) { - if (tail == e) + if (tail == e) { tail = (C *)this->prev(e); + } DLL<C, L>::remove(e); } @@ -605,9 +617,11 @@ inline void Queue<C, L>::append(DLL<C, L> q) { C *qtail = q.head; - if (qtail) - while (this->next(qtail)) + if (qtail) { + while (this->next(qtail)) { qtail = this->next(qtail); + } + } if (!head) { head = q.head; tail = qtail; @@ -640,18 +654,20 @@ template <class C, class L> inline void Queue<C, L>::enqueue(C *e) { - if (tail) + if (tail) { insert(e, tail); - else + } else { push(e); + } } template <class C, class L> inline void Queue<C, L>::in_or_enqueue(C *e) { - if (!this->in(e)) + if (!this->in(e)) { enqueue(e); + } } template <class C, class L> @@ -671,8 +687,9 @@ template <class C, class L = typename C::Link_link> struct SortableQueue : publi void sort() { - if (!head) + if (!head) { return; + } bool clean = false; while (!clean) { clean = true; @@ -683,28 +700,33 @@ template <class C, class L = typename C::Link_link> struct SortableQueue : publi if (*n < *v) { clean = false; // swap 'em - if (head == v) + if (head == v) { head = n; - if (tail == n) + } + if (tail == n) { tail = v; + } // fix prev (p) C *p = this->prev(v); if (p) { this->next(p) = n; this->prev(n) = p; - } else + } else { this->prev(n) = nullptr; + } // fix follow (f) if (f) { this->prev(f) = v; this->next(v) = f; - } else + } else { this->next(v) = nullptr; + } // fix interior this->prev(v) = n; this->next(n) = v; - } else + } else { v = n; + } n = f; } } @@ -744,8 +766,9 @@ inline C * CountQueue<C, L>::pop() { C *ret = Queue<C, L>::pop(); - if (ret) + if (ret) { size--; + } return ret; } @@ -824,10 +847,11 @@ template <class C, class A = DefaultAlloc> struct List { C first() { - if (head) + if (head) { return head->car; - else + } else { return 0; + } } C car() @@ -837,10 +861,11 @@ template <class C, class A = DefaultAlloc> struct List { ConsCell<C, A> * rest() { - if (head) + if (head) { return head->cdr; - else + } else { return 0; + } } ConsCell<C, A> * cdr() diff --git a/include/tscore/MD5.h b/include/tscore/MD5.h index 7d6154727c..41756f308c 100644 --- a/include/tscore/MD5.h +++ b/include/tscore/MD5.h @@ -46,7 +46,7 @@ public: EVP_DigestInit_ex(_ctx, EVP_md5(), nullptr); #endif } - ~MD5Context() + ~MD5Context() override { #if HAVE_MD5_INIT // _md5ctx does not need to be freed diff --git a/include/tscore/MatcherUtils.h b/include/tscore/MatcherUtils.h index 0c7969721e..954081ada6 100644 --- a/include/tscore/MatcherUtils.h +++ b/include/tscore/MatcherUtils.h @@ -122,8 +122,9 @@ const char *parseConfigLine(char *line, matcher_line *p_line, const matcher_tags static inline void LowerCaseStr(char *str) { - if (!str) + if (!str) { return; + } while (*str != '\0') { *str = ParseRules::ink_tolower(*str); str++; diff --git a/include/tscore/ParseRules.h b/include/tscore/ParseRules.h index 10c26df3f1..31e671cc64 100644 --- a/include/tscore/ParseRules.h +++ b/include/tscore/ParseRules.h @@ -174,14 +174,14 @@ public: inline CTypeResult ParseRules::is_type(char c, uint32_t bitmask) { - return (parseRulesCType[(unsigned char)c] & bitmask); + return (parseRulesCType[static_cast<unsigned char>(c)] & bitmask); } inline CTypeResult ParseRules::is_char(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_char_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_char_BIT); #else return ((c & 0x80) == 0); #endif @@ -191,7 +191,7 @@ inline CTypeResult ParseRules::is_upalpha(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_upalpha_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_upalpha_BIT); #else return (c >= 'A' && c <= 'Z'); #endif @@ -201,7 +201,7 @@ inline CTypeResult ParseRules::is_loalpha(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_loalpha_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_loalpha_BIT); #else return (c >= 'a' && c <= 'z'); #endif @@ -211,7 +211,7 @@ inline CTypeResult ParseRules::is_alpha(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_alpha_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_alpha_BIT); #else return (is_upalpha(c) || is_loalpha(c)); #endif @@ -221,7 +221,7 @@ inline CTypeResult ParseRules::is_digit(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_digit_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_digit_BIT); #else return (c >= '0' && c <= '9'); #endif @@ -231,7 +231,7 @@ inline CTypeResult ParseRules::is_alnum(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_alnum_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_alnum_BIT); #else return (is_alpha(c) || is_digit(c)); #endif @@ -241,7 +241,7 @@ inline CTypeResult ParseRules::is_ctl(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_ctl_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_ctl_BIT); #else return ((!(c & 0x80) && c <= 31) || c == 127); #endif @@ -251,7 +251,7 @@ inline CTypeResult ParseRules::is_ws(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_ws_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_ws_BIT); #else return (c == CHAR_SP || c == CHAR_HT); #endif @@ -261,7 +261,7 @@ inline CTypeResult ParseRules::is_hex(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_hex_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_hex_BIT); #else return ((c >= 'A' && c <= 'F') || (c >= 'a' && c <= 'f') || (c >= '0' && c <= '9')); #endif @@ -283,7 +283,7 @@ inline CTypeResult ParseRules::is_splf(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_splf_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_splf_BIT); #else return (c == CHAR_SP || c == CHAR_LF); #endif @@ -293,7 +293,7 @@ inline CTypeResult ParseRules::is_spcr(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_spcr_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_spcr_BIT); #else return (c == CHAR_SP || c == CHAR_CR); #endif @@ -303,7 +303,7 @@ inline CTypeResult ParseRules::is_wslfcr(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_wslfcr_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_wslfcr_BIT); #else return ParseRules::is_ws(c) || ParseRules::is_splf(c) || ParseRules::is_spcr(c); #endif @@ -313,7 +313,7 @@ inline CTypeResult ParseRules::is_extra(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_extra_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_extra_BIT); #else switch (c) { case '!': @@ -332,7 +332,7 @@ inline CTypeResult ParseRules::is_safe(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_safe_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_safe_BIT); #else return (c == '$' || c == '-' || c == '_' || c == '.' || c == '+'); #endif @@ -342,10 +342,11 @@ inline CTypeResult ParseRules::is_unsafe(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_unsafe_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_unsafe_BIT); #else - if (is_ctl(c)) + if (is_ctl(c)) { return (true); + } switch (c) { case ' ': @@ -364,7 +365,7 @@ inline CTypeResult ParseRules::is_reserved(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_reserved_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_reserved_BIT); #else switch (c) { case ';': @@ -384,7 +385,7 @@ inline CTypeResult ParseRules::is_national(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_national_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_national_BIT); #else switch (c) { case '{': @@ -406,7 +407,7 @@ inline CTypeResult ParseRules::is_unreserved(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_unreserved_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_unreserved_BIT); #else return (is_alpha(c) || is_digit(c) || is_safe(c) || is_extra(c) || is_national(c)); #endif @@ -416,7 +417,7 @@ inline CTypeResult ParseRules::is_punct(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_punct_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_punct_BIT); #else switch (c) { case '!': @@ -460,7 +461,7 @@ inline CTypeResult ParseRules::is_end_of_url(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_end_of_url_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_end_of_url_BIT); #else return (c == '\0' || c == '\n' || c == ' ' || ParseRules::is_ctl(c)); #endif @@ -485,13 +486,15 @@ inline CTypeResult ParseRules::is_pchar(const char *seq) { #ifndef COMPILE_PARSE_RULES - if (*seq != '%') - return (parseRulesCType[(uint8_t)*seq] & is_pchar_BIT); - else + if (*seq != '%') { + return (parseRulesCType[static_cast<uint8_t>(*seq)] & is_pchar_BIT); + } else { return is_hex(seq[1]) && is_hex(seq[2]); + } #else - if (is_unreserved(*seq)) + if (is_unreserved(*seq)) { return (true); + } switch (seq[0]) { case ':': @@ -509,7 +512,7 @@ inline CTypeResult ParseRules::is_tspecials(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_tspecials_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_tspecials_BIT); #else switch (c) { case '(': @@ -541,7 +544,7 @@ inline CTypeResult ParseRules::is_token(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_token_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_token_BIT); #else return (is_char(c) && !(is_ctl(c) || is_tspecials(c))); #endif @@ -551,7 +554,7 @@ inline char ParseRules::ink_toupper(char c) { #ifndef COMPILE_PARSE_RULES - return parseRulesCTypeToUpper[(unsigned char)c]; + return parseRulesCTypeToUpper[static_cast<unsigned char>(c)]; #else int up_case = c; const int up_case_diff = 'a' - 'A'; @@ -567,7 +570,7 @@ inline char ParseRules::ink_tolower(char c) { #ifndef COMPILE_PARSE_RULES - return parseRulesCTypeToLower[(unsigned char)c]; + return parseRulesCTypeToLower[static_cast<unsigned char>(c)]; #else int lo_case = c; const int lo_case_diff = 'a' - 'A'; @@ -583,7 +586,7 @@ inline CTypeResult ParseRules::is_eow(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_eow_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_eow_BIT); #else return (c == '\0' || c == '\r' || c == '\n'); #endif @@ -593,10 +596,11 @@ inline CTypeResult ParseRules::is_uri(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_uri_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_uri_BIT); #else - if (is_alnum(c)) + if (is_alnum(c)) { return (true); + } switch (c) { case ':': @@ -632,7 +636,7 @@ inline CTypeResult ParseRules::is_sep(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_sep_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_sep_BIT); #else return (!c || c == ',' || c == ':' || c == '!' || is_wslfcr(c)); #endif @@ -642,7 +646,7 @@ inline CTypeResult ParseRules::is_empty(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_empty_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_empty_BIT); #else return (c == '#' || is_wslfcr(c)); #endif @@ -652,7 +656,7 @@ inline CTypeResult ParseRules::is_space(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_space_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_space_BIT); #else switch (c) { case CHAR_SP: @@ -675,13 +679,13 @@ inline CTypeResult ParseRules::is_control(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_control_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_control_BIT); #else if (c == CHAR_HT || c == CHAR_SP) { return false; } - if (((unsigned char)c) < 0x20 || c == 0x7f) { + if ((static_cast<unsigned char>(c)) < 0x20 || c == 0x7f) { return true; } @@ -693,11 +697,13 @@ inline CTypeResult ParseRules::is_mime_sep(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_mime_sep_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_mime_sep_BIT); #else if ((c == '(') || (c == ')') || (c == '<') || (c == '>') || (c == '@') || (c == ',') || (c == ';') || (c == '\\') || - (c == '\"') || (c == '/') || (c == '[') || (c == ']') || (c == '?') || (c == '{') || (c == '}') || (c == ' ') || (c == '\t')) + (c == '\"') || (c == '/') || (c == '[') || (c == ']') || (c == '?') || (c == '{') || (c == '}') || (c == ' ') || + (c == '\t')) { return true; + } return false; #endif } @@ -706,10 +712,11 @@ inline CTypeResult ParseRules::is_http_field_name(char c) { #ifndef COMPILE_PARSE_RULES - return (parseRulesCType[(unsigned char)c] & is_http_field_name_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_http_field_name_BIT); #else - if ((c == ':') || (is_mime_sep(c) && (c != '@'))) + if ((c == ':') || (is_mime_sep(c) && (c != '@'))) { return false; + } return true; #endif } @@ -718,7 +725,7 @@ inline CTypeResult ParseRules::is_http_field_value(char c) { #ifndef COMPILE_PARSE_RULES - return (CTypeResult)(parseRulesCType[(unsigned char)c] & is_http_field_value_BIT); + return (parseRulesCType[static_cast<unsigned char>(c)] & is_http_field_value_BIT); #else switch (c) { case CHAR_CR: @@ -751,8 +758,9 @@ ParseRules::strncasecmp_eow(const char *s1, const char *s2, int count) /////////////////////////////////////////////////////////////// // if they are different; only match if both are terminators // /////////////////////////////////////////////////////////////// - if (ink_tolower(a) != ink_tolower(b)) + if (ink_tolower(a) != ink_tolower(b)) { return (is_eow(a) && is_eow(b)); + } } return (true); } @@ -767,8 +775,9 @@ inline int ParseRules::strlen_eow(const char *s) { for (int i = 0; true; i++) { - if (is_eow(s[i])) + if (is_eow(s[i])) { return (i); + } } } @@ -787,10 +796,13 @@ ParseRules::strstr_eow(const char *s1, const char *s2) int s2_len = strlen_eow(s2); - for (i1 = 0; !is_eow(s1[i1]); i1++) - if (ink_tolower(s1[i1]) == ink_tolower(s2[0])) - if (strncasecmp_eow(&s1[i1], &s2[0], s2_len)) + for (i1 = 0; !is_eow(s1[i1]); i1++) { + if (ink_tolower(s1[i1]) == ink_tolower(s2[0])) { + if (strncasecmp_eow(&s1[i1], &s2[0], s2_len)) { return (&s1[i1]); + } + } + } return (nullptr); } @@ -802,10 +814,13 @@ ParseRules::strcasestr(const char *s1, const char *s2) size_t s2_len = strlen(s2); - for (i1 = 0; s1[i1] != '\0'; i1++) - if (ink_tolower(s1[i1]) == ink_tolower(s2[0])) - if (strncasecmp_eow(&s1[i1], &s2[0], (int)s2_len)) + for (i1 = 0; s1[i1] != '\0'; i1++) { + if (ink_tolower(s1[i1]) == ink_tolower(s2[0])) { + if (strncasecmp_eow(&s1[i1], &s2[0], static_cast<int>(s2_len))) { return (&s1[i1]); + } + } + } return (nullptr); } @@ -813,28 +828,33 @@ ParseRules::strcasestr(const char *s1, const char *s2) inline const char * ParseRules::memchr(const char *s, char c, int max_length) { - for (int i = 0; i < max_length; i++) - if (s[i] == c) + for (int i = 0; i < max_length; i++) { + if (s[i] == c) { return (&s[i]); + } + } return (nullptr); } inline const char * ParseRules::strchr(const char *s, char c) { - for (int i = 0; s[i] != '\0'; i++) - if (s[i] == c) + for (int i = 0; s[i] != '\0'; i++) { + if (s[i] == c) { return (&s[i]); + } + } return (nullptr); } static inline int ink_get_hex(char c) { - if (ParseRules::is_digit(c)) - return (int)(c - '0'); + if (ParseRules::is_digit(c)) { + return (c - '0'); + } c = ParseRules::ink_tolower(c); - return (int)((c - 'a') + 10); + return ((c - 'a') + 10); } int64_t ink_atoi64(const char *, const char **end = nullptr); @@ -846,12 +866,13 @@ ink_atoi(const char *str) { int64_t val = ink_atoi64(str); - if (val > INT_MAX) + if (val > INT_MAX) { return INT_MAX; - else if (val < INT_MIN) + } else if (val < INT_MIN) { return INT_MIN; - else + } else { return static_cast<int>(val); + } } static inline int @@ -859,12 +880,13 @@ ink_atoi(const char *str, int len) { int64_t val = ink_atoi64(str, len); - if (val > INT_MAX) + if (val > INT_MAX) { return INT_MAX; - else if (val < INT_MIN) + } else if (val < INT_MIN) { return INT_MIN; - else + } else { return static_cast<int>(val); + } } static inline unsigned int @@ -872,8 +894,9 @@ ink_atoui(const char *str) { uint64_t val = ink_atoui64(str); - if (val > UINT_MAX) + if (val > UINT_MAX) { return UINT_MAX; - else + } else { return static_cast<unsigned int>(val); + } } diff --git a/include/tscore/Ptr.h b/include/tscore/Ptr.h index c6dc46525d..97f8d72f8d 100644 --- a/include/tscore/Ptr.h +++ b/include/tscore/Ptr.h @@ -241,8 +241,9 @@ inline void Ptr<T>::clear() { if (m_ptr) { - if (!m_ptr->refcount_dec()) + if (!m_ptr->refcount_dec()) { m_ptr->free(); + } m_ptr = nullptr; } } diff --git a/include/tscore/SHA256.h b/include/tscore/SHA256.h index c80f76f8e0..d9fe13ed77 100644 --- a/include/tscore/SHA256.h +++ b/include/tscore/SHA256.h @@ -46,7 +46,7 @@ public: EVP_DigestInit_ex(_ctx, EVP_sha256(), nullptr); #endif } - ~SHA256Context() + ~SHA256Context() override { #if HAVE_SHA256_INIT // _sha256ctx does not need to be freed diff --git a/include/tscore/SimpleTokenizer.h b/include/tscore/SimpleTokenizer.h index 82a257fff9..86ee779ab7 100644 --- a/include/tscore/SimpleTokenizer.h +++ b/include/tscore/SimpleTokenizer.h @@ -246,14 +246,16 @@ private: // CONSIDER_NULL_FIELDS flag is not set // if (!(_mode & CONSIDER_NULL_FIELDS)) { - while (_data[--end] == delimiter) - ; + while (_data[--end] == delimiter) { + // do nothing + } ++end; } if (!(_mode & KEEP_WHITESPACE_RIGHT)) { - while (isspace(_data[--end])) - ; + while (isspace(_data[--end])) { + // do nothing + } ++end; } diff --git a/include/tscore/TextBuffer.h b/include/tscore/TextBuffer.h index 65dd1ec30a..810010a1bf 100644 --- a/include/tscore/TextBuffer.h +++ b/include/tscore/TextBuffer.h @@ -94,7 +94,7 @@ public: size_t spaceUsed() const { - return (size_t)(nextAdd - bufferStart); + return static_cast<size_t>(nextAdd - bufferStart); }; bool diff --git a/include/tscore/ink_args.h b/include/tscore/ink_args.h index f3b4eedd59..2729d9f0bb 100644 --- a/include/tscore/ink_args.h +++ b/include/tscore/ink_args.h @@ -43,7 +43,7 @@ Process arguments struct ArgumentDescription; class AppVersionInfo; -typedef void ArgumentFunction(const ArgumentDescription *argument_descriptions, unsigned n_argument_descriptions, const char *arg); +using ArgumentFunction = void(const ArgumentDescription *, unsigned int, const char *); struct ArgumentDescription { const char *name; diff --git a/include/tscore/ink_hrtime.h b/include/tscore/ink_hrtime.h index 8e822844e2..9326b15202 100644 --- a/include/tscore/ink_hrtime.h +++ b/include/tscore/ink_hrtime.h @@ -36,7 +36,7 @@ #include <cstdint> #include <sys/time.h> #include <cstdlib> -typedef int64_t ink_hrtime; +using ink_hrtime = int64_t; int squid_timestamp_to_buf(char *buf, unsigned int buf_size, long timestamp_sec, long timestamp_usec); char *int64_to_str(char *buf, unsigned int buf_size, int64_t val, unsigned int *total_chars, unsigned int req_width = 0, @@ -152,49 +152,49 @@ ink_hrtime_from_timeval(const struct timeval *tv) static inline ink_hrtime ink_hrtime_to_years(ink_hrtime t) { - return ((ink_hrtime)(t / HRTIME_YEAR)); + return (t / HRTIME_YEAR); } static inline ink_hrtime ink_hrtime_to_weeks(ink_hrtime t) { - return ((ink_hrtime)(t / HRTIME_WEEK)); + return (t / HRTIME_WEEK); } static inline ink_hrtime ink_hrtime_to_days(ink_hrtime t) { - return ((ink_hrtime)(t / HRTIME_DAY)); + return (t / HRTIME_DAY); } static inline ink_hrtime ink_hrtime_to_mins(ink_hrtime t) { - return ((ink_hrtime)(t / HRTIME_MINUTE)); + return (t / HRTIME_MINUTE); } static inline ink_hrtime ink_hrtime_to_sec(ink_hrtime t) { - return ((ink_hrtime)(t / HRTIME_SECOND)); + return (t / HRTIME_SECOND); } static inline ink_hrtime ink_hrtime_to_msec(ink_hrtime t) { - return ((ink_hrtime)(t / HRTIME_MSECOND)); + return (t / HRTIME_MSECOND); } static inline ink_hrtime ink_hrtime_to_usec(ink_hrtime t) { - return ((ink_hrtime)(t / HRTIME_USECOND)); + return (t / HRTIME_USECOND); } static inline ink_hrtime ink_hrtime_to_nsec(ink_hrtime t) { - return ((ink_hrtime)(t / HRTIME_NSECOND)); + return (t / HRTIME_NSECOND); } static inline struct timespec @@ -249,13 +249,13 @@ ink_gettimeofday() static inline int ink_time() { - return (int)ink_hrtime_to_sec(ink_get_hrtime()); + return static_cast<int>(ink_hrtime_to_sec(ink_get_hrtime())); } static inline int ink_hrtime_diff_msec(ink_hrtime t1, ink_hrtime t2) { - return (int)ink_hrtime_to_msec(t1 - t2); + return static_cast<int>(ink_hrtime_to_msec(t1 - t2)); } static inline ink_hrtime diff --git a/include/tscore/ink_inet.h b/include/tscore/ink_inet.h index e1d1e2ea99..911d563072 100644 --- a/include/tscore/ink_inet.h +++ b/include/tscore/ink_inet.h @@ -806,12 +806,13 @@ ats_ip_addr_cmp(sockaddr const *lhs, ///< Left hand operand. if (AF_INET == rtype) { in_addr_t la = ntohl(ats_ip4_cast(lhs)->sin_addr.s_addr); in_addr_t ra = ntohl(ats_ip4_cast(rhs)->sin_addr.s_addr); - if (la < ra) + if (la < ra) { zret = -1; - else if (la > ra) + } else if (la > ra) { zret = 1; - else + } else { zret = 0; + } } else if (AF_INET6 == rtype) { // IPv4 < IPv6 zret = -1; } else { // IP > not IP @@ -877,10 +878,11 @@ ats_ip_addr_port_eq(sockaddr const *lhs, sockaddr const *rhs) { bool zret = false; if (lhs->sa_family == rhs->sa_family && ats_ip_port_cast(lhs) == ats_ip_port_cast(rhs)) { - if (AF_INET == lhs->sa_family) + if (AF_INET == lhs->sa_family) { zret = ats_ip4_cast(lhs)->sin_addr.s_addr == ats_ip4_cast(rhs)->sin_addr.s_addr; - else if (AF_INET6 == lhs->sa_family) + } else if (AF_INET6 == lhs->sa_family) { zret = 0 == memcmp(&ats_ip6_cast(lhs)->sin6_addr, &ats_ip6_cast(rhs)->sin6_addr, sizeof(in6_addr)); + } } return zret; } diff --git a/include/tscore/ink_llqueue.h b/include/tscore/ink_llqueue.h index 0241da521b..9a38273f64 100644 --- a/include/tscore/ink_llqueue.h +++ b/include/tscore/ink_llqueue.h @@ -31,17 +31,17 @@ A simple linked list queue. #include "tscore/ink_mutex.h" #include "tscore/ink_thread.h" -typedef struct llqrec_s { - struct llqrec_s *next; +struct LLQrec { + struct LLQrec *next; void *data; -} LLQrec; +}; -typedef struct llq_s { +struct LLQ { LLQrec *head, *tail, *free; uint64_t len, highwater; ink_mutex mux; ink_semaphore sema; -} LLQ; +}; LLQ *create_queue(); int enqueue(LLQ *q, void *data); diff --git a/include/tscore/ink_memory.h b/include/tscore/ink_memory.h index a7acbbc3f4..1ed8b6a597 100644 --- a/include/tscore/ink_memory.h +++ b/include/tscore/ink_memory.h @@ -112,16 +112,17 @@ static inline size_t __attribute__((const)) ats_pagesize() { static size_t page_size; - if (page_size) + if (page_size) { return page_size; + } #if defined(HAVE_SYSCONF) && defined(_SC_PAGESIZE) long ret = sysconf(_SC_PAGESIZE); - page_size = (size_t)((ret > -1) ? ret : 8192); + page_size = static_cast<size_t>((ret > -1) ? ret : 8192); #elif defined(HAVE_GETPAGESIZE) page_size = (size_t)getpagesize(); #else - page_size = (size_t)8192; + page_size = static_cast<size_t>(8192); #endif return page_size; @@ -592,10 +593,12 @@ path_join(ats_scoped_str const &lhs, ats_scoped_str const &rhs) size_t rn = strlen(rhs); const char *rptr = rhs; // May need to be modified. - if (ln && lhs[ln - 1] == '/') + if (ln && lhs[ln - 1] == '/') { --ln; // drop trailing separator. - if (rn && *rptr == '/') + } + if (rn && *rptr == '/') { --rn, ++rptr; // drop leading separator. + } ats_scoped_str x(ln + rn + 2); diff --git a/include/tscore/ink_platform.h b/include/tscore/ink_platform.h index 5ceab569aa..97ade74d7f 100644 --- a/include/tscore/ink_platform.h +++ b/include/tscore/ink_platform.h @@ -147,7 +147,7 @@ struct ifafilt; #endif #if defined(__linux__) -typedef unsigned int in_addr_t; +using in_addr_t = unsigned int; #endif #ifdef HAVE_SYS_SYSINFO_H diff --git a/include/tscore/ink_queue.h b/include/tscore/ink_queue.h index edf31e378c..9875ab3e6c 100644 --- a/include/tscore/ink_queue.h +++ b/include/tscore/ink_queue.h @@ -88,8 +88,8 @@ union head_p { typedef int64_t version_type; typedef __int128_t data_type; #else - typedef int64_t version_type; - typedef int64_t data_type; + using version_type = int64_t; + using data_type = int64_t; #endif struct { @@ -192,8 +192,8 @@ struct _InkFreeList { int advice; }; -typedef struct ink_freelist_ops InkFreeListOps; -typedef struct _InkFreeList InkFreeList; +using InkFreeListOps = struct ink_freelist_ops; +using InkFreeList = struct _InkFreeList; const InkFreeListOps *ink_freelist_malloc_ops(); const InkFreeListOps *ink_freelist_freelist_ops(); diff --git a/include/tscore/ink_rand.h b/include/tscore/ink_rand.h index 26db69eab5..5d606d29ee 100644 --- a/include/tscore/ink_rand.h +++ b/include/tscore/ink_rand.h @@ -80,5 +80,5 @@ private: inline int ink_rand_r(uint32_t *p) { - return (((*p) = (*p) * 1103515245 + 12345) % ((uint32_t)0x7fffffff + 1)); + return (((*p) = (*p) * 1103515245 + 12345) % (static_cast<uint32_t>(0x7fffffff) + 1)); } diff --git a/include/tscore/ink_rwlock.h b/include/tscore/ink_rwlock.h index b3bc10f367..553fb2e81f 100644 --- a/include/tscore/ink_rwlock.h +++ b/include/tscore/ink_rwlock.h @@ -32,7 +32,7 @@ #include "tscore/ink_error.h" #include <pthread.h> -typedef pthread_rwlock_t ink_rwlock; +using ink_rwlock = pthread_rwlock_t; void ink_rwlock_init(ink_rwlock *rw); void ink_rwlock_destroy(ink_rwlock *rw); diff --git a/include/tscore/ink_string++.h b/include/tscore/ink_string++.h index 94b286f577..9d737edcc1 100644 --- a/include/tscore/ink_string++.h +++ b/include/tscore/ink_string++.h @@ -74,7 +74,7 @@ struct Str { void dump(FILE *fp = stderr) { - fprintf(fp, "Str [\"%.*s\", len %d]\n", (int)len, str, (int)len); + fprintf(fp, "Str [\"%.*s\", len %d]\n", static_cast<int>(len), str, static_cast<int>(len)); } }; diff --git a/include/tscore/ink_string.h b/include/tscore/ink_string.h index c8e9a736a9..fad97ffc85 100644 --- a/include/tscore/ink_string.h +++ b/include/tscore/ink_string.h @@ -284,7 +284,7 @@ ptr_len_pbrk(const char *p1, int l1, const char *str) while (*str_cur != '\0') { if (*p1 == *str_cur) { - return (char *)p1; + return const_cast<char *>(p1); } str_cur++; } @@ -352,7 +352,7 @@ ink_fast_itoa(int32_t val, char *buf, int buf_len) return (ret >= 0 ? ret : 0); } - return ink_small_itoa((int)val, buf, buf_len); + return ink_small_itoa(static_cast<int>(val), buf, buf_len); } inline int @@ -364,7 +364,7 @@ ink_fast_uitoa(uint32_t val, char *buf, int buf_len) return (ret >= 0 ? ret : 0); } - return ink_small_itoa((int)val, buf, buf_len); + return ink_small_itoa(static_cast<int>(val), buf, buf_len); } inline int @@ -376,7 +376,7 @@ ink_fast_ltoa(int64_t val, char *buf, int buf_len) return (ret >= 0 ? ret : 0); } - return ink_small_itoa((int)val, buf, buf_len); + return ink_small_itoa(static_cast<int>(val), buf, buf_len); } /// Check for prefix. diff --git a/include/tscore/ink_thread.h b/include/tscore/ink_thread.h index 644c587a42..b4a9f45a24 100644 --- a/include/tscore/ink_thread.h +++ b/include/tscore/ink_thread.h @@ -54,9 +54,9 @@ #define INK_MUTEX_INIT PTHREAD_MUTEX_INITIALIZER #define INK_THREAD_STACK_MIN PTHREAD_STACK_MIN -typedef pthread_t ink_thread; -typedef pthread_cond_t ink_cond; -typedef pthread_key_t ink_thread_key; +using ink_thread = pthread_t; +using ink_cond = pthread_cond_t; +using ink_thread_key = pthread_key_t; // Darwin has a sem_init stub that returns ENOSYS. Rather than bodge around doing runtime // detection, just emulate on Darwin. @@ -90,7 +90,7 @@ struct ink_semaphore { ******************************************************************/ #ifdef POSIX_THREAD_10031c -typedef struct timespec ink_timestruc; +using ink_timestruc = struct timespec; #else typedef timestruc_t ink_timestruc; #endif @@ -173,7 +173,7 @@ ink_thread_null() // The implementation of ink_thread (the alias of pthread_t) is different on platforms // - e.g. `struct pthread *` on Unix and `unsigned long int` on Linux // NOLINTNEXTLINE(modernize-use-nullptr) - return (ink_thread)0; + return static_cast<ink_thread>(0); } static inline int @@ -241,8 +241,9 @@ static inline int ink_cond_timedwait(ink_cond *cp, ink_mutex *mp, ink_timestruc *t) { int err; - while (EINTR == (err = pthread_cond_timedwait(cp, mp, t))) + while (EINTR == (err = pthread_cond_timedwait(cp, mp, t))) { ; + } #if defined(freebsd) || defined(openbsd) ink_assert((err == 0) || (err == ETIMEDOUT)); #else diff --git a/include/tscore/signals.h b/include/tscore/signals.h index 3726d42471..d0a9940574 100644 --- a/include/tscore/signals.h +++ b/include/tscore/signals.h @@ -28,7 +28,7 @@ #pragma once -typedef void (*signal_handler_t)(int signo, siginfo_t *info, void *ctx); +using signal_handler_t = void (*)(int, siginfo_t *, void *); // Default crash signal handler that dumps a stack trace and exits. void signal_crash_handler(int, siginfo_t *, void *); diff --git a/include/tscpp/util/Histogram.h b/include/tscpp/util/Histogram.h index 5a88997adf..f01b8d5d7d 100644 --- a/include/tscpp/util/Histogram.h +++ b/include/tscpp/util/Histogram.h @@ -65,17 +65,17 @@ public: /// Number of bits to split each base range in to span buckets. static constexpr raw_type N_SPAN_BITS = S; /// Number of buckets per span. - static constexpr raw_type N_SPAN_BUCKETS = raw_type(1) << N_SPAN_BITS; + static constexpr raw_type N_SPAN_BUCKETS = static_cast<raw_type>(1) << N_SPAN_BITS; /// Mask to extract the local bucket index from a sample. - static constexpr raw_type SPAN_MASK = (raw_type(1) << N_SPAN_BITS) - 1; + static constexpr raw_type SPAN_MASK = (static_cast<raw_type>(1) << N_SPAN_BITS) - 1; /// Initial mask to find the MSB in the sample. - static constexpr raw_type MSB_MASK = raw_type(1) << (N_RANGE_BITS + N_SPAN_BITS - 1); + static constexpr raw_type MSB_MASK = static_cast<raw_type>(1) << (N_RANGE_BITS + N_SPAN_BITS - 1); /// Total number of buckets - 1 for overflow and an extra range for less than @c UNDERFLOW_BOUND static constexpr raw_type N_BUCKETS = ((N_RANGE_BITS + 1) * N_SPAN_BUCKETS) + 1; /// Samples less than this go in the underflow range. - static constexpr raw_type UNDERFLOW_BOUND = raw_type(1) << N_SPAN_BITS; + static constexpr raw_type UNDERFLOW_BOUND = static_cast<raw_type>(1) << N_SPAN_BITS; /// Sample equal or greater than this go in the overflow bucket. - static constexpr raw_type OVERFLOW_BOUND = raw_type(1) << (N_RANGE_BITS + N_SPAN_BITS + 1); + static constexpr raw_type OVERFLOW_BOUND = static_cast<raw_type>(1) << (N_RANGE_BITS + N_SPAN_BITS + 1); /** Add @sample to the histogram. * diff --git a/src/tscore/HKDF_openssl3.cc b/src/tscore/HKDF_openssl3.cc index 30c190dc80..4f951bf4e1 100644 --- a/src/tscore/HKDF_openssl3.cc +++ b/src/tscore/HKDF_openssl3.cc @@ -27,10 +27,10 @@ HKDF::HKDF(const char *digest) { - EVP_KDF *kdf = EVP_KDF_fetch(NULL, "HKDF", NULL); + EVP_KDF *kdf = EVP_KDF_fetch(nullptr, "HKDF", nullptr); this->_kctx = EVP_KDF_CTX_new(kdf); EVP_KDF_free(kdf); - *params = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, (char *)digest, strlen(digest)); + *params = OSSL_PARAM_construct_utf8_string(OSSL_KDF_PARAM_DIGEST, const_cast<char *>(digest), strlen(digest)); } HKDF::~HKDF() @@ -45,8 +45,8 @@ HKDF::extract(uint8_t *dst, size_t *dst_len, const uint8_t *salt, size_t salt_le size_t keysize; int mode = EVP_KDF_HKDF_MODE_EXTRACT_ONLY; OSSL_PARAM *p = params + 1; - *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, (uint8_t *)ikm, ikm_len); - *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT, (uint8_t *)salt, salt_len); + *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, const_cast<uint8_t *>(ikm), ikm_len); + *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_SALT, const_cast<uint8_t *>(salt), salt_len); *p++ = OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE, &mode); *p = OSSL_PARAM_construct_end(); @@ -71,8 +71,8 @@ HKDF::expand(uint8_t *dst, size_t *dst_len, const uint8_t *prk, size_t prk_len, { int mode = EVP_KDF_HKDF_MODE_EXPAND_ONLY; OSSL_PARAM *p = params + 1; - *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, (uint8_t *)prk, prk_len); - *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO, (uint8_t *)info, info_len); + *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_KEY, const_cast<uint8_t *>(prk), prk_len); + *p++ = OSSL_PARAM_construct_octet_string(OSSL_KDF_PARAM_INFO, const_cast<uint8_t *>(info), info_len); *p++ = OSSL_PARAM_construct_int(OSSL_KDF_PARAM_MODE, &mode); *p = OSSL_PARAM_construct_end(); if (EVP_KDF_derive(_kctx, dst, length, params) <= 0) { diff --git a/src/tscore/MMH.cc b/src/tscore/MMH.cc index 1d1d5868ef..ec04feb266 100644 --- a/src/tscore/MMH.cc +++ b/src/tscore/MMH.cc @@ -329,10 +329,10 @@ ink_code_incr_MMH_final(uint8_t *presult, MMH_CTX *ctx) // final phase uint32_t *b = reinterpret_cast<uint32_t *>(presult); uint64_t d = ((static_cast<uint64_t>(1)) << 32) + 15; - uint32_t b0 = uint32_t(ctx->state[0] % d); - uint32_t b1 = uint32_t(ctx->state[1] % d); - uint32_t b2 = uint32_t(ctx->state[2] % d); - uint32_t b3 = uint32_t(ctx->state[3] % d); + uint32_t b0 = static_cast<uint32_t>(ctx->state[0] % d); + uint32_t b1 = static_cast<uint32_t>(ctx->state[1] % d); + uint32_t b2 = static_cast<uint32_t>(ctx->state[2] % d); + uint32_t b3 = static_cast<uint32_t>(ctx->state[3] % d); // scramble the bits, losslessly (reversibly) b[0] = b0; b[1] = b1 ^ (b0 >> 24) ^ (b0 << 8); diff --git a/src/tscore/Regex.cc b/src/tscore/Regex.cc index fb318443bf..516d51e803 100644 --- a/src/tscore/Regex.cc +++ b/src/tscore/Regex.cc @@ -132,7 +132,7 @@ Regex::exec(std::string_view const &str, int *ovector, int ovecsize) const { int rv; - rv = pcre_exec(regex, regex_extra, str.data(), int(str.size()), 0, 0, ovector, ovecsize); + rv = pcre_exec(regex, regex_extra, str.data(), static_cast<int>(str.size()), 0, 0, ovector, ovecsize); return rv > 0; } diff --git a/src/tscore/ink_stack_trace.cc b/src/tscore/ink_stack_trace.cc index ace71496b6..283d436e94 100644 --- a/src/tscore/ink_stack_trace.cc +++ b/src/tscore/ink_stack_trace.cc @@ -91,8 +91,9 @@ void ink_stack_trace_dump() { const char msg[] = "ink_stack_trace_dump not implemented on this operating system\n"; - if (write(STDERR_FILENO, msg, sizeof(msg) - 1) == -1) + if (write(STDERR_FILENO, msg, sizeof(msg) - 1) == -1) { return; + } } const void * diff --git a/src/tscore/unit_tests/test_ArgParser.cc b/src/tscore/unit_tests/test_ArgParser.cc index 8405bcf288..ff88785c48 100644 --- a/src/tscore/unit_tests/test_ArgParser.cc +++ b/src/tscore/unit_tests/test_ArgParser.cc @@ -52,7 +52,7 @@ TEST_CASE("Parsing test", "[parse]") ts::Arguments parsed_data; // first run of arguments - const char *argv1[] = {"traffic_blabla", "init", "a", "--initoption", "--globalx", "x", "y", NULL}; + const char *argv1[] = {"traffic_blabla", "init", "a", "--initoption", "--globalx", "x", "y", nullptr}; parsed_data = parser.parse(argv1); REQUIRE(parsed_data.get("init") == true); @@ -74,7 +74,7 @@ TEST_CASE("Parsing test", "[parse]") // second run of arguments const char *argv2[] = {"traffic_blabla", "init", "i", "subinit", "a", "b", - "--initoption2=abc", "--subinitopt", "-y", "y1", "y2", NULL}; + "--initoption2=abc", "--subinitopt", "-y", "y1", "y2", nullptr}; parsed_data = parser.parse(argv2); REQUIRE(parsed_data.get("init") == true); @@ -90,7 +90,7 @@ TEST_CASE("Parsing test", "[parse]") // third run of arguments const char *argv3[] = {"traffic_blabla", "-x", "abc", "xyz", "remove", "subremove", - "subsubremove", "--globalz=z1", "--globalz=z2", "--globalz=z3", NULL}; + "subsubremove", "--globalz=z1", "--globalz=z2", "--globalz=z3", nullptr}; parsed_data = parser.parse(argv3); REQUIRE(parsed_data.has_action() == false); @@ -131,7 +131,7 @@ TEST_CASE("Invoke test", "[invoke]") ts::Arguments parsed_data; - const char *argv1[] = {"traffic_blabla", "func", NULL}; + const char *argv1[] = {"traffic_blabla", "func", nullptr}; parsed_data = parser2.parse(argv1); REQUIRE(parsed_data.has_action() == true); @@ -139,7 +139,7 @@ TEST_CASE("Invoke test", "[invoke]") REQUIRE(global == 0); REQUIRE(parser2.get_error() == "error"); - const char *argv2[] = {"traffic_blabla", "func2", NULL}; + const char *argv2[] = {"traffic_blabla", "func2", nullptr}; parsed_data = parser2.parse(argv2); parsed_data.invoke(); diff --git a/src/tscore/unit_tests/test_Encoding.cc b/src/tscore/unit_tests/test_Encoding.cc index ad1b0bb600..b23d7c3475 100644 --- a/src/tscore/unit_tests/test_Encoding.cc +++ b/src/tscore/unit_tests/test_Encoding.cc @@ -52,7 +52,7 @@ TEST_CASE("Encoding pure escapify url", "[pure_esc_url]") int n = sizeof(input) / sizeof(input[0]); for (int i = 0; i < n; ++i) { - Encoding::pure_escapify_url(NULL, input[i], std::strlen(input[i]), &output_len, output, 128); + Encoding::pure_escapify_url(nullptr, input[i], std::strlen(input[i]), &output_len, output, 128); CHECK(std::string_view(output) == expected[i]); } } @@ -76,7 +76,7 @@ TEST_CASE("Encoding escapify url", "[esc_url]") int n = sizeof(input) / sizeof(input[0]); for (int i = 0; i < n; ++i) { - Encoding::escapify_url(NULL, input[i], std::strlen(input[i]), &output_len, output, 128); + Encoding::escapify_url(nullptr, input[i], std::strlen(input[i]), &output_len, output, 128); CHECK(std::string_view(output) == expected[i]); } } diff --git a/src/tscore/unit_tests/test_Extendible.cc b/src/tscore/unit_tests/test_Extendible.cc index a7cf4f073e..01af903a0b 100644 --- a/src/tscore/unit_tests/test_Extendible.cc +++ b/src/tscore/unit_tests/test_Extendible.cc @@ -37,8 +37,12 @@ TEST_CASE("AtomicBit Atomic test") // test the atomicity and isolation of operations uint32_t bit_storage = 0; - auto job_set = [&bit_storage](int idx) { AtomicBit{(uint8_t *)&bit_storage + (idx / 8), (uint8_t)(1 << (idx % 8))} = 1; }; - auto job_clear = [&bit_storage](int idx) { AtomicBit{(uint8_t *)&bit_storage + (idx / 8), (uint8_t)(1 << (idx % 8))} = 0; }; + auto job_set = [&bit_storage](int idx) { + AtomicBit{reinterpret_cast<uint8_t *>(&bit_storage) + (idx / 8), static_cast<uint8_t>(1 << (idx % 8))} = true; + }; + auto job_clear = [&bit_storage](int idx) { + AtomicBit{reinterpret_cast<uint8_t *>(&bit_storage) + (idx / 8), static_cast<uint8_t>(1 << (idx % 8))} = false; + }; std::thread jobs[32]; @@ -46,8 +50,8 @@ TEST_CASE("AtomicBit Atomic test") for (int i = 0; i < 32; i++) { jobs[i] = std::thread(job_set, i); } - for (int i = 0; i < 32; i++) { - jobs[i].join(); + for (auto &job : jobs) { + job.join(); } REQUIRE(bit_storage == 0xffffffff); @@ -55,8 +59,8 @@ TEST_CASE("AtomicBit Atomic test") for (int i = 0; i < 32; i++) { jobs[i] = std::thread(job_clear, i); } - for (int i = 0; i < 32; i++) { - jobs[i].join(); + for (auto &job : jobs) { + job.join(); } REQUIRE(bit_storage == 0); } @@ -161,7 +165,7 @@ TEST_CASE("Extendible Memory Allocations", "") // 0 1 2 3 4 5 6 //[ EA*, a, b,EC*, c, EA, EC] // - uint16_t *mem = (uint16_t *)&x; + uint16_t *mem = reinterpret_cast<uint16_t *>(&x); CHECK(memDelta(&x, &x.a) == w * 1); CHECK(memDelta(&x, &x.b) == w * 2); CHECK(memDelta(&x, &x.c) == w * 4); @@ -260,7 +264,7 @@ DerivedExtalloc() void DerivedExtFree(void *ptr) { - delete (Derived *)ptr; + delete static_cast<Derived *>(ptr); } ExtFieldContext @@ -387,7 +391,7 @@ TEST_CASE("Extendible", "") CHECK(ext::viewFormat(ref) == Derived::testFormat()); AtomicBit bitref = ext::set(ref, bit_a); - bitref = 1; + bitref = true; CHECK(bitref == true); bitref = true; CHECK(bitref == true); @@ -426,9 +430,9 @@ TEST_CASE("Extendible", "") REQUIRE_THAT(ext::toString(ref), Contains("bit_b: 0")); REQUIRE_THAT(ext::toString(ref), Contains("bit_c: 0")); - ext::set(ref, bit_a) = 1; - ext::set(ref, bit_b) = 0; - ext::set(ref, bit_c) = 1; + ext::set(ref, bit_a) = true; + ext::set(ref, bit_b) = false; + ext::set(ref, bit_c) = true; CHECK(ext::get(ref, bit_a) == true); CHECK(ext::get(ref, bit_b) == false); CHECK(ext::get(ref, bit_c) == true); @@ -497,14 +501,14 @@ TEST_CASE("Extendible C API") REQUIRE(d != nullptr); ExtFieldContext cf_a = DerivedExtfieldFind("cf_a"); - uint8_t *data8 = (uint8_t *)ExtFieldPtr(d, cf_a); + uint8_t *data8 = static_cast<uint8_t *>(ExtFieldPtr(d, cf_a)); CHECK(data8[0] == 0); ink_atomic_increment(&data8[0], 1); data8[1] = 5; data8[2] = 7; - uint32_t *data32 = (uint32_t *)ExtFieldPtr(d, cf_a); + uint32_t *data32 = static_cast<uint32_t *>(ExtFieldPtr(d, cf_a)); CHECK(*data32 == 0x00070501); DerivedExtFree(d); } diff --git a/src/tscore/unit_tests/test_MMH.cc b/src/tscore/unit_tests/test_MMH.cc index 53b30e9579..72781ec64e 100644 --- a/src/tscore/unit_tests/test_MMH.cc +++ b/src/tscore/unit_tests/test_MMH.cc @@ -55,8 +55,8 @@ TEST_CASE("MMH", "[libts][MMH]") uint32_t h[4]; } h; - xxh = (i4_t *)ats_malloc(4 * sizeof(uint32_t) * TEST_COLLISIONS); - xf = (double *)ats_malloc(sizeof(double) * TEST_COLLISIONS); + xxh = static_cast<i4_t *>(ats_malloc(4 * sizeof(uint32_t) * TEST_COLLISIONS)); + xf = static_cast<double *>(ats_malloc(sizeof(double) * TEST_COLLISIONS)); printf("test collisions\n"); const char *sc1 = "http://npdev:19080/1.6664000000/4000"; @@ -77,29 +77,30 @@ TEST_CASE("MMH", "[libts][MMH]") char xs[256]; xf[xx] = ts::Random::drandom(); snprintf(xs, sizeof(xs), "http://@npdev/%16.14f/4000;?", xf[xx]); - ink_code_MMH((unsigned char *)xs, strlen(xs), (unsigned char *)&xxh[xx]); + ink_code_MMH(reinterpret_cast<unsigned char *>(xs), strlen(xs), reinterpret_cast<unsigned char *>(&xxh[xx])); } qsort(xxh, TEST_COLLISIONS, 16, xxcompar); for (int xy = 0; xy < TEST_COLLISIONS - 1; xy++) { if (xxh[xy][0] == xxh[xy + 1][0] && xxh[xy][1] == xxh[xy + 1][1] && xxh[xy][2] == xxh[xy + 1][2] && - xxh[xy][3] == xxh[xy + 1][3]) + xxh[xy][3] == xxh[xy + 1][3]) { printf("********** collision %d\n", xy); + } } ats_free(xf); ats_free(xxh); - unsigned char *s = (unsigned char *)MMH_x; + unsigned char *s = reinterpret_cast<unsigned char *>(MMH_x); int l = sizeof(MMH_x); - unsigned char *s1 = (unsigned char *)ats_malloc(l + sizeof(uint32_t)); + unsigned char *s1 = static_cast<unsigned char *>(ats_malloc(l + sizeof(uint32_t))); unsigned char *free_s1 = s1; s1 += 1; memcpy(s1, s, l); - unsigned char *s2 = (unsigned char *)ats_malloc(l + sizeof(uint32_t)); + unsigned char *s2 = static_cast<unsigned char *>(ats_malloc(l + sizeof(uint32_t))); unsigned char *free_s2 = s2; s2 += 2; memcpy(s2, s, l); - unsigned char *s3 = (unsigned char *)ats_malloc(l + sizeof(uint32_t)); + unsigned char *s3 = static_cast<unsigned char *>(ats_malloc(l + sizeof(uint32_t))); unsigned char *free_s3 = s3; s3 += 3; memcpy(s3, s, l); @@ -120,7 +121,7 @@ TEST_CASE("MMH", "[libts][MMH]") printf("test chunking\n"); ink_code_incr_MMH_init(&c); for (i = 0; i < 24; i++) { - ink_code_incr_MMH_update(&c, (char *)t, i); + ink_code_incr_MMH_update(&c, reinterpret_cast<char *>(t), i); t += i; } ink_code_incr_MMH_final((uint8_t *)h.hash, &c); @@ -136,14 +137,15 @@ TEST_CASE("MMH", "[libts][MMH]") size_t total = 0; for (size_t xx = 0; ((xx = fread(x, 1, 128, fp)) == 128) && total < 1048576; total += xx) { - ink_code_MMH((unsigned char *)x, 128, h.hash); + ink_code_MMH(reinterpret_cast<unsigned char *>(x), 128, h.hash); hist[h.h[0] & 255]++; total += xx; } for (int z = 0; z < 256; z++) { printf("%6d ", hist[z]); - if (!(z % 7)) + if (!(z % 7)) { printf("\n"); + } } printf("\n"); diff --git a/src/tscore/unit_tests/test_Random.cc b/src/tscore/unit_tests/test_Random.cc index 7d4b6a6619..3b8b24d0c4 100644 --- a/src/tscore/unit_tests/test_Random.cc +++ b/src/tscore/unit_tests/test_Random.cc @@ -41,12 +41,12 @@ TEST_CASE("test random", "[libts][random]") ts::Random::random(); } auto diff = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now() - start); - std::cout << std::endl << (double)diff.count() / 1000000 << " ns per Random::random()" << std::endl; + std::cout << std::endl << static_cast<double>(diff.count()) / 1000000 << " ns per Random::random()" << std::endl; start = std::chrono::high_resolution_clock::now(); for (auto i = 0; i < 1000000; ++i) { x.random(); } diff = std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now() - start); - std::cout << (double)diff.count() / 1000000 << " ns per InkRand::random()" << std::endl; + std::cout << static_cast<double>(diff.count()) / 1000000 << " ns per InkRand::random()" << std::endl; } diff --git a/src/tscore/unit_tests/test_arena.cc b/src/tscore/unit_tests/test_arena.cc index 01f4217f0e..ae37893e8e 100644 --- a/src/tscore/unit_tests/test_arena.cc +++ b/src/tscore/unit_tests/test_arena.cc @@ -67,7 +67,7 @@ TEST_CASE("test arena", "[libts][arena]") // Allocate and fill the array for (j = 0; j < regions_to_test; j++) { - test_regions[j] = (char *)a->alloc(test_size); + test_regions[j] = static_cast<char *>(a->alloc(test_size)); fill_test_data(test_regions[j], test_size, j); }