[glib: 2/8] gapplicationcommandline: Handle the possibility empty args in an example




commit 0d743e7ffbf1edff5e00e67a9bed7bfa507901f6
Author: Philip Withnall <pwithnall endlessos org>
Date:   Mon Jan 31 14:46:08 2022 +0000

    gapplicationcommandline: Handle the possibility empty args in an example
    
    While it’s not usual, it is possible for applications to be called with
    an empty `argv` by a process (ab)using `execve()`. Modify the
    `GApplication` code example to handle that possibility, so that anyone
    copying the example isn’t introducing a bug into their program
    immediately.
    
    Signed-off-by: Philip Withnall <pwithnall endlessos org>

 gio/gapplicationcommandline.c | 6 ++++++
 1 file changed, 6 insertions(+)
---
diff --git a/gio/gapplicationcommandline.c b/gio/gapplicationcommandline.c
index 937b87d22..d7be108bf 100644
--- a/gio/gapplicationcommandline.c
+++ b/gio/gapplicationcommandline.c
@@ -119,6 +119,12 @@
  *
  *   argv = *arguments;
  *
+ *   if (argv[0] == NULL)
+ *     {
+ *       *exit_status = 0;
+ *       return FALSE;
+ *     }
+ *
  *   i = 1;
  *   while (argv[i])
  *     {


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