[ovs-dev] [PATCH 03/15] dhcp: Don't pass NULL to memcmp() even with size 0.

Ben Pfaff blp at nicira.com
Wed Feb 10 19:30:26 UTC 2010


ISO C says that the arguments to memcmp() must be nonnull even if the
size argument is 0, so don't do that.

Found by Clang (http://clang-analyzer.llvm.org).
---
 lib/dhcp.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/lib/dhcp.c b/lib/dhcp.c
index f0c3644..51d6ed0 100644
--- a/lib/dhcp.c
+++ b/lib/dhcp.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2008 Nicira Networks.
+ * Copyright (c) 2008, 2010 Nicira Networks.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -497,7 +497,7 @@ dhcp_option_equals(const struct dhcp_option *a, const struct dhcp_option *b)
 {
     return ((a->data != NULL) == (b->data != NULL)
             && a->n == b->n
-            && !memcmp(a->data, b->data, a->n));
+            && (!a->data || !memcmp(a->data, b->data, a->n)));
 }
 
 /* Replaces 'ds' by a string representation of 'msg'.  If 'multiline' is
-- 
1.6.6.1





More information about the dev mailing list