[glib] Reduce false positives in static analysis



commit 8b3853b8a1cc94767c5391808274f931a48f6cbb
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Sep 18 19:16:11 2009 -0400

    Reduce false positives in static analysis
    
    Tools like clang fail to recognize that stanzas like
    g_return_if_fail (GTK_IS_FOO (w)) guarantee w != NULL. By minimally
    rewriting the type-checking macros, we can avoid these false positives.

 gobject/gtype.h |   12 +++++++++---
 1 files changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/gobject/gtype.h b/gobject/gtype.h
index 1eeccde..7920ec2 100644
--- a/gobject/gtype.h
+++ b/gobject/gtype.h
@@ -1475,7 +1475,9 @@ G_GNUC_INTERNAL void    g_signal_init           (void); /* sync with gsignal.c *
 #ifdef	__GNUC__
 #  define _G_TYPE_CIT(ip, gt)             (G_GNUC_EXTENSION ({ \
   GTypeInstance *__inst = (GTypeInstance*) ip; GType __t = gt; gboolean __r; \
-  if (__inst && __inst->g_class && __inst->g_class->g_type == __t) \
+  if (!__inst) \
+    __r = FALSE; \
+  else if (__inst->g_class && __inst->g_class->g_type == __t) \
     __r = TRUE; \
   else \
     __r = g_type_check_instance_is_a (__inst, __t); \
@@ -1483,7 +1485,9 @@ G_GNUC_INTERNAL void    g_signal_init           (void); /* sync with gsignal.c *
 }))
 #  define _G_TYPE_CCT(cp, gt)             (G_GNUC_EXTENSION ({ \
   GTypeClass *__class = (GTypeClass*) cp; GType __t = gt; gboolean __r; \
-  if (__class && __class->g_type == __t) \
+  if (!__class) \
+    __r = FALSE; \
+  else if (__class->g_type == __t) \
     __r = TRUE; \
   else \
     __r = g_type_check_class_is_a (__class, __t); \
@@ -1491,7 +1495,9 @@ G_GNUC_INTERNAL void    g_signal_init           (void); /* sync with gsignal.c *
 }))
 #  define _G_TYPE_CVH(vl, gt)             (G_GNUC_EXTENSION ({ \
   GValue *__val = (GValue*) vl; GType __t = gt; gboolean __r; \
-  if (__val && __val->g_type == __t) \
+  if (!__val) \
+    __r = FALSE; \
+  if (__val->g_type == __t) \
     __r = TRUE; \
   else \
     __r = g_type_check_value_holds (__val, __t); \



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