From aff303190de8985f17e516e81e0a13c4cb353d4a Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Fri, 10 Sep 2021 13:55:59 +0300 Subject: [PATCH 1/3] src: Fix the API of `KeymapManager::add_user_mode()` Cppcheck produces the following warning: ``` keymap_manager.hh:54:37: performance: Function parameter 'user_mode_name' should be passed by const reference. ``` Fixes #4340 --- src/keymap_manager.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/keymap_manager.hh b/src/keymap_manager.hh index 64e39dd7..7474ed95 100644 --- a/src/keymap_manager.hh +++ b/src/keymap_manager.hh @@ -51,7 +51,7 @@ public: return m_parent->user_modes(); return m_user_modes; } - void add_user_mode(const String user_mode_name); + void add_user_mode(String user_mode_name); private: KeymapManager() From 367879ddcf7f332a04cc844ad683caf1c94c933c Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Fri, 10 Sep 2021 14:16:51 +0300 Subject: [PATCH 2/3] src: Use pre-increment iterator syntax Cppcheck produces the following warning: ``` string_utils.cc:24:9: performance: Prefer prefix ++/-- operators for non-primitive types. ``` Fixes #4340 --- src/string_utils.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/string_utils.cc b/src/string_utils.cc index 212cab2e..459bea0b 100644 --- a/src/string_utils.cc +++ b/src/string_utils.cc @@ -21,7 +21,7 @@ String trim_indent(StringView str) utf8::iterator it{str.begin(), str}; while (it != str.end() and is_horizontal_blank(*it)) - it++; + ++it; const StringView indent{str.begin(), it.base()}; return accumulate(str | split_after('\n') | transform([&](auto&& line) { From c57a86ce6264a4b141dfb462964e4dad3c1b154c Mon Sep 17 00:00:00 2001 From: Frank LENORMAND Date: Fri, 10 Sep 2021 16:34:38 +0300 Subject: [PATCH 3/3] src: Fix undefined behaviour Cppcheck produces the following warnings: ``` shared_string.hh:27:49: portability: Shifting signed 32-bit value by 31 bits is implementation-defined behaviour shared_string.hh:27:49: error: Signed integer overflow for expression '1<<31'. ``` Fixes #4340 --- src/shared_string.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/shared_string.hh b/src/shared_string.hh index a2c0345a..8455a31e 100644 --- a/src/shared_string.hh +++ b/src/shared_string.hh @@ -24,7 +24,7 @@ struct StringData : UseMemoryDomain private: StringData(int len) : refcount(0), length(len) {} - static constexpr uint32_t interned_flag = 1 << 31; + static constexpr uint32_t interned_flag = 1u << 31; static constexpr uint32_t refcount_mask = ~interned_flag; struct PtrPolicy