[glib: 4/5] glib/goption.c: Replace precondition with assertion



commit 651e3b05d8f4e6f6e3f417ff36a8f25efb8d0217
Author: Colin Walters <walters verbum org>
Date:   Mon Aug 19 23:17:30 2019 +0200

    glib/goption.c: Replace precondition with assertion
    
    A static analysis run noted that we weren't freeing the cmdline in the
    error path here.  We can just make this an assertion instead; I just
    checked the kernel code, and it just usees a seq_printf() here which
    will NUL terminate.

 glib/goption.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
---
diff --git a/glib/goption.c b/glib/goption.c
index 183e9d9d3..0f9732c04 100644
--- a/glib/goption.c
+++ b/glib/goption.c
@@ -1829,9 +1829,10 @@ platform_get_argv0 (void)
                            &len,
                            NULL))
     return NULL;
+
   /* Sanity check for a NUL terminator. */
-  if (!memchr (cmdline, 0, len))
-    return NULL;
+  g_assert (memchr (cmdline, 0, len));
+
   /* We could just return cmdline, but I think it's better
    * to hold on to a smaller malloc block; the arguments
    * could be large.


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