Hello!
In this file, when building with recent compiler clang-21, I get the two warnings:
variable '...' is used uninitialized whenever 'if' condition is false.
It happens for identifier line 35, and keystring line 106.
Something like this would probably work:
void handle_key_down(const char* keystring, void* user_data) {
- const char* identifier;
-
std::string val = keystring;
auto result = std::find_if(hotkey_id_map.begin(), hotkey_id_map.end(),
[val](const auto& e) { return e.second == val; });
- if (result != hotkey_id_map.end())
- identifier = result->first.c_str();
-
- g_autoptr(FlValue) event_data = fl_value_new_map();
- fl_value_set_string_take(event_data, "identifier",
- fl_value_new_string(identifier));
- FlValue* event = fl_value_new_map();
- fl_value_set_string_take(event, "type", fl_value_new_string("onKeyDown"));
- fl_value_set_string_take(event, "data", event_data);
- fl_event_channel_send(event_channel, event, nullptr, nullptr);
+ if (result != hotkey_id_map.end()) {
+ const char* identifier = result->first.c_str();
+ g_autoptr(FlValue) event_data = fl_value_new_map();
+ fl_value_set_string_take(event_data, "identifier",
+ fl_value_new_string(identifier));
+ FlValue* event = fl_value_new_map();
+ fl_value_set_string_take(event, "type", fl_value_new_string("onKeyDown"));
+ fl_value_set_string_take(event, "data", event_data);
+ }
}
static FlMethodResponse* hkm_unregister(_HotkeyManagerLinuxPlugin* self,
FlValue* args) {
const char* identifier =
fl_value_get_string(fl_value_lookup_string(args, "identifier"));
- const char* keystring;
std::string val = identifier;
auto result = std::find_if(hotkey_id_map.begin(), hotkey_id_map.end(),
[val](const auto& e) { return e.first == val; });
- if (result != hotkey_id_map.end())
- keystring = result->second.c_str();
-
- keybinder_unbind(keystring, handle_key_down);
- hotkey_id_map.erase(identifier);
-
- return FL_METHOD_RESPONSE(
- fl_method_success_response_new(fl_value_new_bool(true)));
+ auto removed = false;
+
+ if (result != hotkey_id_map.end()) {
+ const char* keystring = result->second.c_str();
+ keybinder_unbind(keystring, handle_key_down);
+ hotkey_id_map.erase(identifier);
+ removed = true;
+ }
+ return FL_METHOD_RESPONSE(
+ fl_method_success_response_new(fl_value_new_bool(removed)));
}
Thanks 🙂
Hello!
In this file, when building with recent compiler clang-21, I get the two warnings:
variable '...' is used uninitialized whenever 'if' condition is false.It happens for
identifierline 35, andkeystringline 106.Something like this would probably work:
void handle_key_down(const char* keystring, void* user_data) { - const char* identifier; - std::string val = keystring; auto result = std::find_if(hotkey_id_map.begin(), hotkey_id_map.end(), [val](const auto& e) { return e.second == val; }); - if (result != hotkey_id_map.end()) - identifier = result->first.c_str(); - - g_autoptr(FlValue) event_data = fl_value_new_map(); - fl_value_set_string_take(event_data, "identifier", - fl_value_new_string(identifier)); - FlValue* event = fl_value_new_map(); - fl_value_set_string_take(event, "type", fl_value_new_string("onKeyDown")); - fl_value_set_string_take(event, "data", event_data); - fl_event_channel_send(event_channel, event, nullptr, nullptr); + if (result != hotkey_id_map.end()) { + const char* identifier = result->first.c_str(); + g_autoptr(FlValue) event_data = fl_value_new_map(); + fl_value_set_string_take(event_data, "identifier", + fl_value_new_string(identifier)); + FlValue* event = fl_value_new_map(); + fl_value_set_string_take(event, "type", fl_value_new_string("onKeyDown")); + fl_value_set_string_take(event, "data", event_data); + } } static FlMethodResponse* hkm_unregister(_HotkeyManagerLinuxPlugin* self, FlValue* args) { const char* identifier = fl_value_get_string(fl_value_lookup_string(args, "identifier")); - const char* keystring; std::string val = identifier; auto result = std::find_if(hotkey_id_map.begin(), hotkey_id_map.end(), [val](const auto& e) { return e.first == val; }); - if (result != hotkey_id_map.end()) - keystring = result->second.c_str(); - - keybinder_unbind(keystring, handle_key_down); - hotkey_id_map.erase(identifier); - - return FL_METHOD_RESPONSE( - fl_method_success_response_new(fl_value_new_bool(true))); + auto removed = false; + + if (result != hotkey_id_map.end()) { + const char* keystring = result->second.c_str(); + keybinder_unbind(keystring, handle_key_down); + hotkey_id_map.erase(identifier); + removed = true; + } + return FL_METHOD_RESPONSE( + fl_method_success_response_new(fl_value_new_bool(removed))); }Thanks 🙂