summarylogtreecommitdiffstats
path: root/pr74.patch
blob: 7d906bce6254711e751fa3fd2f94b674f02c12e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
From bffed5eb181127df915002b6ed830f85f15feafd Mon Sep 17 00:00:00 2001
From: NicBOMB <19939315+NicBOMB@users.noreply.github.com>
Date: Sat, 2 Jul 2022 14:46:15 -0700
Subject: [PATCH 1/4] Fix #72 and #73

Add missing include statements.
credit @Arian8j2 https://github.com/keyleds/keyleds/issues/72#issue-1241282805
---
 keyledsd/plugins/src/lua/LuaEffect.cxx | 1 +
 keyledsd/src/service/EffectManager.cxx | 1 +
 keyledsd/src/tools/Paths.cxx           | 1 +
 3 files changed, 3 insertions(+)
 mode change 100644 => 100755 keyledsd/plugins/src/lua/LuaEffect.cxx
 mode change 100644 => 100755 keyledsd/src/service/EffectManager.cxx

diff --git a/keyledsd/plugins/src/lua/LuaEffect.cxx b/keyledsd/plugins/src/lua/LuaEffect.cxx
old mode 100644
new mode 100755
index eccc65b..1c2a902
--- a/keyledsd/plugins/src/lua/LuaEffect.cxx
+++ b/keyledsd/plugins/src/lua/LuaEffect.cxx
@@ -19,6 +19,7 @@
 #include "lua/Environment.h"
 #include "lua/lua_common.h"
 #include <algorithm>
+#include <array>
 #include <cassert>
 #include <cstring>
 #include <lua.hpp>
diff --git a/keyledsd/src/service/EffectManager.cxx b/keyledsd/src/service/EffectManager.cxx
old mode 100644
new mode 100755
index bb76e54..04f25bb
--- a/keyledsd/src/service/EffectManager.cxx
+++ b/keyledsd/src/service/EffectManager.cxx
@@ -20,6 +20,7 @@
 #include "keyledsd/plugin/module.h"
 #include "keyledsd/tools/DynamicLibrary.h"
 #include <algorithm>
+#include <array>
 #include <unistd.h>
 
 LOGGING("effect-manager");
diff --git a/keyledsd/src/tools/Paths.cxx b/keyledsd/src/tools/Paths.cxx
index bd8de35..59c1206 100644
--- a/keyledsd/src/tools/Paths.cxx
+++ b/keyledsd/src/tools/Paths.cxx
@@ -18,6 +18,7 @@
 
 #include "config.h"
 #include <algorithm>
+#include <array>
 #include <cassert>
 #include <cstdlib>
 #include <fstream>

From 8c4049e4099e20f701bcb6bd83ef42035cad5812 Mon Sep 17 00:00:00 2001
From: NicBOMB <19939315+NicBOMB@users.noreply.github.com>
Date: Sun, 3 Jul 2022 09:44:32 -0700
Subject: [PATCH 2/4] code cleanup utilizing cppcheck suggestions

---
 keyledsd/plugins/src/PluginHelper.cxx  |  8 +++-----
 keyledsd/plugins/src/fill.cxx          |  4 ++--
 keyledsd/src/service/Configuration.cxx |  4 ++--
 keyledsd/src/service/DeviceManager.cxx |  4 ++--
 keyledsd/src/tools/Paths.cxx           |  2 +-
 keyledsd/tests/KeyDatabase.cxx         | 16 +++++++++++-----
 keyledsd/tests/RenderTarget.cxx        |  7 ++++++-
 7 files changed, 27 insertions(+), 18 deletions(-)
 mode change 100644 => 100755 keyledsd/plugins/src/PluginHelper.cxx
 mode change 100644 => 100755 keyledsd/plugins/src/fill.cxx
 mode change 100644 => 100755 keyledsd/src/service/Configuration.cxx
 mode change 100644 => 100755 keyledsd/src/service/DeviceManager.cxx
 mode change 100644 => 100755 keyledsd/src/tools/Paths.cxx
 mode change 100644 => 100755 keyledsd/tests/KeyDatabase.cxx

diff --git a/keyledsd/plugins/src/PluginHelper.cxx b/keyledsd/plugins/src/PluginHelper.cxx
old mode 100644
new mode 100755
index 9a1e97b..eb4af3f
--- a/keyledsd/plugins/src/PluginHelper.cxx
+++ b/keyledsd/plugins/src/PluginHelper.cxx
@@ -26,7 +26,7 @@ std::optional<detail::variant_wrapper> getConfig(const EffectService & service,
 {
     const auto & config = service.configuration();
     auto it = std::find_if(config.begin(), config.end(),
-                           [key](auto & item) { return item.first == key; });
+                           [key](const auto & item) { return item.first == key; });
     if (it != config.end()) { return std::ref(it->second); }
     return std::nullopt;
 }
@@ -36,7 +36,7 @@ detail::get_config<RGBAColor>::parse(const EffectService & service, const altern
 {
     const auto & colors = service.colors();
     auto it = std::find_if(colors.begin(), colors.end(),
-                           [&str](auto & item) { return item.first == str; });
+                           [&str](const auto & item) { return item.first == str; });
     if (it != colors.end()) { return it->second; }
     return RGBAColor::parse(str);
 }
@@ -75,10 +75,8 @@ getColorsCompatibility(EffectService & service, const char * key)
 {
     using std::to_string;
     auto result = std::vector<RGBAColor>{};
-
-    std::string currentKey;
     for (unsigned idx = 0; ; ++idx) {
-        currentKey = key;
+        std::string currentKey = key;
         currentKey.pop_back();
         currentKey += to_string(idx);
         auto value = getConfig(service, currentKey.c_str());
diff --git a/keyledsd/plugins/src/fill.cxx b/keyledsd/plugins/src/fill.cxx
old mode 100644
new mode 100755
index 396a658..57134f5
--- a/keyledsd/plugins/src/fill.cxx
+++ b/keyledsd/plugins/src/fill.cxx
@@ -45,13 +45,13 @@ class FillEffect final : public SimpleEffect
             auto color = parseConfig<RGBAColor>(service, std::get<std::string>(item.second));
 
             if (group && color) {
-                std::for_each(group->begin(), group->end(), [this, &color](auto & key) {
+                std::for_each(group->begin(), group->end(), [this, &color](const auto & key) {
                     m_buffer[key.index] = *color;
                 });
             }
         }
 
-        bool hasAlpha = std::any_of(m_buffer.begin(), m_buffer.end(), [](auto & val) {
+        bool hasAlpha = std::any_of(m_buffer.begin(), m_buffer.end(), [](const auto & val) {
             return val.alpha < std::numeric_limits<RGBAColor::channel_type>::max();
         });
         m_mode = hasAlpha ? Mode::Blend : Mode::Overwrite;
diff --git a/keyledsd/src/service/Configuration.cxx b/keyledsd/src/service/Configuration.cxx
old mode 100644
new mode 100755
index 73434ce..6e4a8ad
--- a/keyledsd/src/service/Configuration.cxx
+++ b/keyledsd/src/service/Configuration.cxx
@@ -287,7 +287,7 @@ class ConfigurationParser::EffectListState final : public State
         auto & builder = parser.as<ConfigurationParser>();
         auto conf = state.as<EffectState>().result();
         auto it_name = std::find_if(conf.cbegin(), conf.cend(),
-                                    [](auto & item) { return item.first == "effect" ||
+                                    [](const auto & item) { return item.first == "effect" ||
                                                              item.first == "plugin"; });
         if (it_name == conf.end() || !std::holds_alternative<std::string>(it_name->second)) {
             throw builder.makeError("plugin configuration must have a name");
@@ -668,7 +668,7 @@ Configuration Configuration::loadFile(const std::string & path)
 std::string getDeviceName(const Configuration & config, const std::string & serial)
 {
     auto dit = std::find_if(config.devices.begin(), config.devices.end(),
-                            [&serial](auto & item) { return item.second == serial; });
+                            [&serial](const auto & item) { return item.second == serial; });
     return dit != config.devices.end() ? dit->first : serial;
 }
 
diff --git a/keyledsd/src/service/DeviceManager.cxx b/keyledsd/src/service/DeviceManager.cxx
old mode 100644
new mode 100755
index 14bba0d..cd7780c
--- a/keyledsd/src/service/DeviceManager.cxx
+++ b/keyledsd/src/service/DeviceManager.cxx
@@ -163,7 +163,7 @@ std::vector<keyleds::plugin::Effect *> DeviceManager::loadEffects(const string_m
     for (const auto & name : profile->effectGroups) {
         auto eit = std::find_if(m_configuration->effectGroups.begin(),
                                 m_configuration->effectGroups.end(),
-                                [&name](auto & group) { return group.name == name; });
+                                [&name](const auto & group) { return group.name == name; });
         if (eit == m_configuration->effectGroups.end()) {
             ERROR("profile <", profile->name, "> references unknown effect group <", name, ">");
             continue;
@@ -174,7 +174,7 @@ std::vector<keyleds::plugin::Effect *> DeviceManager::loadEffects(const string_m
         for (const auto & name : overlayProfile->effectGroups) {
             auto eit = std::find_if(m_configuration->effectGroups.begin(),
                                     m_configuration->effectGroups.end(),
-                                    [&name](auto & group) { return group.name == name; });
+                                    [&name](const auto & group) { return group.name == name; });
             if (eit == m_configuration->effectGroups.end()) {
                 ERROR("profile <", profile->name, "> references unknown effect group <", name, ">");
                 continue;
diff --git a/keyledsd/src/tools/Paths.cxx b/keyledsd/src/tools/Paths.cxx
old mode 100644
new mode 100755
index 59c1206..e4fb064
--- a/keyledsd/src/tools/Paths.cxx
+++ b/keyledsd/src/tools/Paths.cxx
@@ -104,7 +104,7 @@ static std::string canonicalPath(const std::string & path)
 std::vector<std::string> keyleds::tools::paths::getPaths(XDG type, bool extra)
 {
     auto specIt = std::find_if(variables.begin(), variables.end(),
-                               [type](auto & item) { return item.type == type; });
+                               [type](const auto & item) { return item.type == type; });
     if (specIt == variables.end()) {
         throw std::out_of_range("Invalid XDG variable");
     }
diff --git a/keyledsd/tests/KeyDatabase.cxx b/keyledsd/tests/KeyDatabase.cxx
old mode 100644
new mode 100755
index 04fa2e4..e0ad4f3
--- a/keyledsd/tests/KeyDatabase.cxx
+++ b/keyledsd/tests/KeyDatabase.cxx
@@ -57,8 +57,10 @@ TEST_F(KeyDatabaseTest, requirements) {
         static_assert(std::is_swappable_v<KeyDatabase::const_iterator>);
         static_assert(std::is_same_v<decltype(*i), const KeyDatabase::value_type &>);
         static_assert(std::is_convertible_v<decltype(++i), KeyDatabase::const_iterator>);
+        // cppcheck-suppress postfixOperator
         static_assert(std::is_convertible_v<decltype(i++), KeyDatabase::const_iterator>);
         static_assert(std::is_convertible_v<decltype(--i), KeyDatabase::const_iterator>);
+        // cppcheck-suppress postfixOperator
         static_assert(std::is_convertible_v<decltype(i--), KeyDatabase::const_iterator>);
         static_assert(std::is_convertible_v<decltype(i == j), bool>);
         static_assert(std::is_convertible_v<decltype(i != j), bool>);
@@ -78,17 +80,18 @@ TEST_F(KeyDatabaseTest, construct) {
 TEST_F(KeyDatabaseTest, iterator) {
     // Range-for to sum indices
     unsigned sum = 0;
+    // cppcheck-suppress useStlAlgorithm
     for (auto & item : m_db) { sum += item.index; }
     EXPECT_EQ((m_db.size()-1) * m_db.size() / 2, sum);
 
     // STL algorithm to sum indices
     sum = std::accumulate(m_db.begin(), m_db.end(), 0u,
-                          [](unsigned val, auto & key) { return val + key.index; });
+                          [](unsigned val, const auto & key) { return val + key.index; });
     EXPECT_EQ((m_db.size()-1) * m_db.size() / 2, sum);
 
     // STL find some arbitrary key
     auto it = std::find_if(m_db.begin(), m_db.end(),
-                           [&](auto & key) { return key.name == m_db[3].name; });
+                           [&](const auto & key) { return key.name == m_db[3].name; });
     EXPECT_EQ(m_db.begin() + 3, it);
 }
 
@@ -142,8 +145,10 @@ TEST_F(KeyGroupTest, requirements) {
         static_assert(std::is_swappable_v<KeyDatabase::KeyGroup::const_iterator>);
         static_assert(std::is_same_v<decltype(*i), const KeyDatabase::KeyGroup::value_type &>);
         static_assert(std::is_convertible_v<decltype(++i), KeyDatabase::KeyGroup::const_iterator>);
+        // cppcheck-suppress postfixOperator
         static_assert(std::is_convertible_v<decltype(i++), KeyDatabase::KeyGroup::const_iterator>);
         static_assert(std::is_convertible_v<decltype(--i), KeyDatabase::KeyGroup::const_iterator>);
+        // cppcheck-suppress postfixOperator
         static_assert(std::is_convertible_v<decltype(i--), KeyDatabase::KeyGroup::const_iterator>);
         static_assert(std::is_convertible_v<decltype(i == j), bool>);
         static_assert(std::is_convertible_v<decltype(i != j), bool>);
@@ -182,17 +187,18 @@ TEST_F(KeyGroupTest, construct) {
 TEST_F(KeyGroupTest, iterator) {
     // Range-for to sum indices
     unsigned sum = 0;
+    // cppcheck-suppress useStlAlgorithm
     for (auto & key : bottom) { sum += key.index; }
     EXPECT_EQ(4, sum);
 
     // STL algorithm to sum indices
     sum = std::accumulate(bottom.begin(), bottom.end(), 0u,
-                          [](unsigned val, auto & key) { return val + key.index; });
+                          [](unsigned val, const auto & key) { return val + key.index; });
     EXPECT_EQ(4, sum);
 
     // STL find some arbitrary key
     auto it = std::find_if(bottom.begin(), bottom.end(),
-                           [](auto & key) { return key.name == "BOTTOMLEFT"; });
+                           [](const auto & key) { return key.name == "BOTTOMLEFT"; });
     EXPECT_EQ(bottom.begin() + 1, it);
 
 }
@@ -205,7 +211,7 @@ TEST_F(KeyGroupTest, clear) {
 
 TEST_F(KeyGroupTest, erase) {
     auto copy = bottom;
-    auto it = std::find_if(copy.begin(), copy.end(), [](auto & key) { return key.name == "BOTTOMRIGHT"; });
+    auto it = std::find_if(copy.begin(), copy.end(), [](const auto & key) { return key.name == "BOTTOMRIGHT"; });
     ASSERT_NE(copy.end(), it);
     copy.erase(it);
     EXPECT_EQ(copy, m_db.makeGroup("test", std::vector{"BOTTOMLEFT"s}));
diff --git a/keyledsd/tests/RenderTarget.cxx b/keyledsd/tests/RenderTarget.cxx
index 8359fd7..94d2ea2 100644
--- a/keyledsd/tests/RenderTarget.cxx
+++ b/keyledsd/tests/RenderTarget.cxx
@@ -41,8 +41,10 @@ TEST(RenderTargetTest, requirements) {
         static_assert(std::is_swappable_v<RenderTarget::iterator>);
         static_assert(std::is_same_v<decltype(*i), RenderTarget::value_type &>);
         static_assert(std::is_convertible_v<decltype(++i), RenderTarget::iterator>);
+        // cppcheck-suppress postfixOperator
         static_assert(std::is_convertible_v<decltype(i++), RenderTarget::iterator>);
         static_assert(std::is_convertible_v<decltype(--i), RenderTarget::iterator>);
+        // cppcheck-suppress postfixOperator
         static_assert(std::is_convertible_v<decltype(i--), RenderTarget::iterator>);
         static_assert(std::is_convertible_v<decltype(i == j), bool>);
         static_assert(std::is_convertible_v<decltype(i != j), bool>);
@@ -56,8 +58,10 @@ TEST(RenderTargetTest, requirements) {
         static_assert(std::is_swappable_v<RenderTarget::const_iterator>);
         static_assert(std::is_same_v<decltype(*i), const RenderTarget::value_type &>);
         static_assert(std::is_convertible_v<decltype(++i), RenderTarget::const_iterator>);
+        // cppcheck-suppress postfixOperator
         static_assert(std::is_convertible_v<decltype(i++), RenderTarget::const_iterator>);
         static_assert(std::is_convertible_v<decltype(--i), RenderTarget::const_iterator>);
+        // cppcheck-suppress postfixOperator
         static_assert(std::is_convertible_v<decltype(i--), RenderTarget::const_iterator>);
         static_assert(std::is_convertible_v<decltype(i == j), bool>);
         static_assert(std::is_convertible_v<decltype(i != j), bool>);
@@ -96,6 +100,7 @@ TEST(RenderTargetTest, move) {
     EXPECT_EQ(RGBAColor(0x11, 0x22, 0x33, 0x44), targetA[0]);
 
     targetB = RenderTarget(13);
+    // cppcheck-suppress redundantAssignment
     targetB = std::move(targetA);   // move assignment, non-empty target
     EXPECT_TRUE(targetA.empty());
     ASSERT_FALSE(targetB.empty());
@@ -110,8 +115,8 @@ TEST(RenderTargetTest, move) {
 
 TEST(RenderTargetTest, iterator) {
     auto target = RenderTarget(7);
-
     for (auto & item : target) {
+        // cppcheck-suppress useStlAlgorithm
         item = RGBAColor{0x11, 0x22, 0x33, 0x44};
     }
     for (auto & item : const_cast<const RenderTarget &>(target)) {

From c30e19f03a07e494d2aed5ae6a5b08f9e438c512 Mon Sep 17 00:00:00 2001
From: NicBOMB <19939315+NicBOMB@users.noreply.github.com>
Date: Sun, 3 Jul 2022 09:46:22 -0700
Subject: [PATCH 3/4] minimally clarify what the FIXME refers to

---
 keyledsctl/src/dev_enum_hard.c | 7 ++++++-
 keyledsctl/src/dev_enum_udev.c | 5 +++++
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/keyledsctl/src/dev_enum_hard.c b/keyledsctl/src/dev_enum_hard.c
index 3f711e2..f493de7 100644
--- a/keyledsctl/src/dev_enum_hard.c
+++ b/keyledsctl/src/dev_enum_hard.c
@@ -67,10 +67,15 @@ bool enum_list_devices(struct dev_enum_item ** out, unsigned * out_nb)
             items[items_nb].vendor_id = devinfo.vendor;
             items[items_nb].product_id = devinfo.product;
             items[items_nb].serial = NULL;
-            items[items_nb].description = NULL; /*FIXME*/
+            items[items_nb].description = NULL;
             items_nb += 1;
         }
 
+        /* FIXME 'items'
+         * dev_enum_hard.c:64:13: error: Common realloc mistake: 'items' nulled but not freed upon failure [memleakOnRealloc]
+         *  items = realloc(items, (items_nb + 1) * sizeof(struct dev_enum_item));
+         */
+
         keyleds_close(device);
     }
     closedir(dir);
diff --git a/keyledsctl/src/dev_enum_udev.c b/keyledsctl/src/dev_enum_udev.c
index d6c5b77..1f34094 100644
--- a/keyledsctl/src/dev_enum_udev.c
+++ b/keyledsctl/src/dev_enum_udev.c
@@ -201,6 +201,11 @@ bool enum_list_devices(struct dev_enum_item ** out, unsigned * out_nb)
         fill_info_structure(usbdev, hiddev, &items[items_nb]);
         items_nb += 1;
 
+        /* FIXME 'items'
+         * dev_enum_udev.c:200:9: error: Common realloc mistake: 'items' nulled but not freed upon failure [memleakOnRealloc]
+         *     items = realloc(items, (items_nb + 1) * sizeof(items[0]));
+         */
+
 err_enum_release_device:
         udev_device_unref(hiddev);
     }

From 5445fe3137813eda6d727cf5874ec9e40873129f Mon Sep 17 00:00:00 2001
From: NicBOMB <19939315+NicBOMB@users.noreply.github.com>
Date: Sun, 3 Jul 2022 09:48:06 -0700
Subject: [PATCH 4/4] remove unused pointer

---
 keyledsd/src/device/Logitech.cxx | 2 --
 1 file changed, 2 deletions(-)
 mode change 100644 => 100755 keyledsd/src/device/Logitech.cxx

diff --git a/keyledsd/src/device/Logitech.cxx b/keyledsd/src/device/Logitech.cxx
old mode 100644
new mode 100755
index 94b761c..087ee9e
--- a/keyledsd/src/device/Logitech.cxx
+++ b/keyledsd/src/device/Logitech.cxx
@@ -205,8 +205,6 @@ std::string Logitech::getName(struct keyleds_device * device)
     if (!keyleds_get_device_name(device, KEYLEDS_TARGET_DEFAULT, &name)) {
         throw error(keyleds_get_error_str(), keyleds_get_errno());
     }
-    // Wrap the pointer in a smart pointer in case string creation throws
-    auto name_p = keyleds_ptr<char[], keyleds_device_name_deleter>(name);
     return std::string(name);
 }