From c577bc89cd591eb50288f16c624a3ef60fd4c654 Mon Sep 17 00:00:00 2001 From: Philip Withnall Date: Tue, 12 Nov 2019 21:15:13 +0000 Subject: [PATCH] gsignal: Warn if g_signal_lookup() is called on an invalid signal name And add a test for it. Signed-off-by: Philip Withnall --- gobject/gsignal.c | 3 +++ gobject/tests/signals.c | 25 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/gobject/gsignal.c b/gobject/gsignal.c index 579eb4846..e610056d6 100644 --- a/gobject/gsignal.c +++ b/gobject/gsignal.c @@ -1331,6 +1331,9 @@ g_signal_lookup (const gchar *name, else if (!g_type_class_peek (itype)) g_warning (G_STRLOC ": unable to look up signal \"%s\" of unloaded type '%s'", name, g_type_name (itype)); + else if (!is_valid_signal_name (name)) + g_warning (G_STRLOC ": unable to look up invalid signal name \"%s\" on type '%s'", + name, g_type_name (itype)); } return signal_id; diff --git a/gobject/tests/signals.c b/gobject/tests/signals.c index 0864f2a31..ae8bd9dc2 100644 --- a/gobject/tests/signals.c +++ b/gobject/tests/signals.c @@ -1311,6 +1311,30 @@ test_lookup (void) g_type_class_unref (test_class); } +static void +test_lookup_invalid (void) +{ + g_test_summary ("Test that g_signal_lookup() emits a warning if looking up an invalid signal name."); + + if (g_test_subprocess ()) + { + GTypeClass *test_class; + guint signal_id; + + test_class = g_type_class_ref (test_get_type ()); + + signal_id = g_signal_lookup ("", test_get_type ()); + g_assert_cmpint (signal_id, ==, 0); + + g_type_class_unref (test_class); + return; + } + + g_test_trap_subprocess (NULL, 0, 0); + g_test_trap_assert_failed (); + g_test_trap_assert_stderr ("*WARNING*unable to look up invalid signal name*"); +} + static void test_parse_name (void) { @@ -1455,6 +1479,7 @@ main (int argc, g_test_add_func ("/gobject/signals/test-disconnection-wrong-object", test_signal_disconnect_wrong_object); g_test_add_func ("/gobject/signals/clear-signal-handler", test_clear_signal_handler); g_test_add_func ("/gobject/signals/lookup", test_lookup); + g_test_add_func ("/gobject/signals/lookup/invalid", test_lookup_invalid); g_test_add_func ("/gobject/signals/parse-name", test_parse_name); g_test_add_func ("/gobject/signals/parse-name/invalid", test_parse_name_invalid); g_test_add_data_func ("/gobject/signals/invalid-name/colon", "my_int:hello", test_signals_invalid_name);