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

Re: [libvirt] [PATCH 01/14] viralloc: Adjust definition of VIR_FREE() for Coverity



On 01/22/13 15:15, John Ferlan wrote:
The Coverity static analyzer was generating many false positives for the
unary operation inside the VIR_FREE() definition as it was trying to evaluate
the else portion of the "?:" even though the if portion was (1).
---
  src/util/viralloc.h | 11 ++++++++++-
  1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/src/util/viralloc.h b/src/util/viralloc.h
index 37ec5ee..0c9b177 100644
--- a/src/util/viralloc.h
+++ b/src/util/viralloc.h
@@ -365,7 +365,16 @@ void virFree(void *ptrptr) ATTRIBUTE_NONNULL(1);
   * while evaluating ptr only once.  For now, we intentionally cast
   * away const, since a number of callers safely pass const char *.
   */
-# define VIR_FREE(ptr) virFree((void *) (1 ? (const void *) &(ptr) : (ptr)))
+# if !STATIC_ANALYSIS
+#  define VIR_FREE(ptr) virFree((void *) (1 ? (const void *) &(ptr) : (ptr)))
+# else
+/* The Coverity static analyzer considers the else path of the "?:" and
+ * flags the VIR_FREE() of the address of the address of memory as a
+ * RESOURCE_LEAK resulting in numerous false positives (eg, VIR_FREE(&ptr))
+ */
+#  define VIR_FREE(ptr) virFree((void *) ((const void *) &(ptr)))
+# endif
+

Uh, this is black magic to me. I leave this one on Eric who added the ternary magic.

Peter



  # if TEST_OOM



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