summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPhilip Withnall <philip.withnall@collabora.co.uk>2014-06-09 14:55:25 +0100
committerPhilip Withnall <philip.withnall@collabora.co.uk>2014-06-09 14:55:25 +0100
commit9feeb03d0c92008367bd7023fcac41e980b23f77 (patch)
tree5a8c7c6e51e7351b8595e9b0f492dfb493736b7a /tests
parenteb33b69cb3b36eb18b5ef4fd803b48d8dfd7cbcd (diff)
gsignal: Ensure string parameters to signal callbacks are expected const
Otherwise the handlers could modify the strings.
Diffstat (limited to 'tests')
-rw-r--r--tests/gsignal-connect.c24
-rw-r--r--tests/gsignal.head.c13
2 files changed, 37 insertions, 0 deletions
diff --git a/tests/gsignal-connect.c b/tests/gsignal-connect.c
index dc63a53..6d34bd6 100644
--- a/tests/gsignal-connect.c
+++ b/tests/gsignal-connect.c
@@ -172,3 +172,27 @@
g_signal_connect (some_object, "invalid-signal",
(GCallback) object_notify_cb, NULL);
}
+
+/*
+ * Incorrect type for argument ‘key’ in signal handler for signal ‘GSettings::changed’. Expected ‘const char *’ but saw ‘gchar *’.
+ * (GCallback) settings_changed_cb, NULL);
+ * ^
+ * note: expanded from macro 'g_signal_connect'
+ * g_signal_connect_data ((instance), (detailed_signal), (c_handler), (data), NULL, (GConnectFlags) 0)
+ * ^
+ */
+{
+ // Signal handler doesn't mark the key as 'const'.
+ GSettings *settings = g_malloc (5); // only checking the type
+ g_signal_connect (settings, "changed",
+ (GCallback) settings_changed_cb, NULL);
+}
+
+/*
+ * No error
+ */
+{
+ GSettings *settings = g_malloc (5); // only checking the type
+ g_signal_connect (settings, "changed",
+ (GCallback) settings_changed_const_cb, NULL);
+}
diff --git a/tests/gsignal.head.c b/tests/gsignal.head.c
index 8b6e1ac..e4f3026 100644
--- a/tests/gsignal.head.c
+++ b/tests/gsignal.head.c
@@ -77,6 +77,19 @@ object_notify_extra_parameter_cb (GObject *gobject, GParamSpec *pspec,
/* Something */
}
+static void
+settings_changed_cb (GSettings *settings, gchar *key, gpointer user_data)
+{
+ /* Something */
+}
+
+static void
+settings_changed_const_cb (GSettings *settings, const gchar *key,
+ gpointer user_data)
+{
+ /* Something */
+}
+
int
main (void)
{