Skip to content

Build warnings (converted to error when building with -Werror) on clang-21. #73

Description

@Laefy

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 🙂

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions