From 829816c5ae19349d5f79c30d635a4c43d8c87813 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Artur=20=C5=9Awigo=C5=84?= Date: Mon, 4 Mar 2024 15:47:56 +0100 Subject: [PATCH] Use strdup() wrapper The wrapper can be used to gracefully accept a null argument and guarantee a non-null return value, and not have to pollute the code with null checks. Change-Id: I46ebe4151787e72e2df0dfea247294e47ba72abf (cherry picked from commit 9e5c7fe2073536a9edfb9a6c1cf0d2afa824b5ac) --- src/e_dispatch_key_event.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/e_dispatch_key_event.c b/src/e_dispatch_key_event.c index 6acf199..a795e38 100644 --- a/src/e_dispatch_key_event.c +++ b/src/e_dispatch_key_event.c @@ -4,6 +4,8 @@ #include "e_mod_utils.h" #include "e_screen_reader_private.h" +#include + static Eina_Bool during_event = EINA_FALSE; static double time_between_presses = 0.01; @@ -14,6 +16,14 @@ typedef struct _KeyEventData { Eldbus_Connection *conn; } KeyEventData; +static char *_xstrdup(const char *str) +{ + char *copy = strdup(str ? str : ""); + assert(copy != NULL); + return copy; +} +#pragma GCC poison strdup + static Ecore_Event_Key * _create_key_event(KeyEventData *ked) { @@ -25,10 +35,10 @@ _create_key_event(KeyEventData *ked) return NULL; } - ev->keyname = strdup(ked->info.keyname); - ev->key = strdup(ked->info.keyname); - ev->string = strdup(ked->info.keyname); - ev->compose = strdup(ked->info.keyname); + ev->keyname = _xstrdup(ked->info.keyname); + ev->key = _xstrdup(ked->info.keyname); + ev->string = _xstrdup(ked->info.keyname); + ev->compose = _xstrdup(ked->info.keyname); ev->window = e_comp->ee_win; ev->event_window = e_comp->ee_win; ev->root_window = e_comp->ee_win; @@ -115,7 +125,7 @@ _e_dispatch_key_event(KeyEventInfo kei, Eldbus_Connection *conn, const Eldbus_Me if (!ked) return eldbus_message_error_new(msg, "org.freedesktop.DBus.Error.Failed", "Malloc error."); - ked->info.keyname = strdup(kei.keyname); + ked->info.keyname = _xstrdup(kei.keyname); ked->info.multiplicity = kei.multiplicity; ked->info.hold_time = kei.hold_time; ked->keycode = _get_keycode_from_string(kei.keyname); -- 2.7.4