[glib/cancellable-cancel-null] gcancellable: add back lost NULL check in g_cancellable_cancel()



commit e13c646465fee03c813251fcd1bbf258f359055d
Author: Christoph Reiter <creiter src gnome org>
Date:   Tue Mar 5 16:44:16 2019 +0100

    gcancellable: add back lost NULL check in g_cancellable_cancel()
    
    Commit f975858e86 removed the NULL check in g_cancellable_cancel() by
    accident which makes it crash when called with NULL.
    
    Add the check back and add a test so this doesn't happen again.
    
    Fixes #1710

 gio/gcancellable.c      | 2 +-
 gio/tests/cancellable.c | 7 +++++++
 2 files changed, 8 insertions(+), 1 deletion(-)
---
diff --git a/gio/gcancellable.c b/gio/gcancellable.c
index 32605ce025..31e990f3c6 100644
--- a/gio/gcancellable.c
+++ b/gio/gcancellable.c
@@ -484,7 +484,7 @@ g_cancellable_cancel (GCancellable *cancellable)
 {
   GCancellablePrivate *priv;
 
-  if (g_cancellable_is_cancelled (cancellable))
+  if (cancellable == NULL || g_cancellable_is_cancelled (cancellable))
     return;
 
   priv = cancellable->priv;
diff --git a/gio/tests/cancellable.c b/gio/tests/cancellable.c
index e06650ed86..0446282289 100644
--- a/gio/tests/cancellable.c
+++ b/gio/tests/cancellable.c
@@ -216,12 +216,19 @@ test_cancel_multiple_concurrent (void)
   g_main_loop_unref (loop);
 }
 
+static void
+test_cancel_null (void)
+{
+  g_cancellable_cancel (NULL);
+}
+
 int
 main (int argc, char *argv[])
 {
   g_test_init (&argc, &argv, NULL);
 
   g_test_add_func ("/cancellable/multiple-concurrent", test_cancel_multiple_concurrent);
+  g_test_add_func ("/cancellable/null", test_cancel_null);
 
   return g_test_run ();
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]