]> granicus.if.org Git - graphviz/commitdiff
remove undefined behavior in VPSC Constraint output
authorMatthew Fernandez <matthew.fernandez@gmail.com>
Sun, 13 Sep 2020 03:51:17 +0000 (20:51 -0700)
committerMatthew Fernandez <matthew.fernandez@gmail.com>
Sat, 19 Sep 2020 16:42:59 +0000 (09:42 -0700)
The address of a reference parameter can never be NULL. A reference parameter
is, definitionally, non-NULL. So taking the address of a reference parameter and
comparing it against NULL is always false. None of the call sites of this
operator passed in NULL, so this change is a no-op from a user perspective, but
it guards against future misuse.

This addresses the following Coverity warning:

  Error: COMPILER_WARNING: [#def230]
  graphviz-2.40.1/lib/vpsc/constraint.cpp: scope_hint: In function 'std::ostream& operator<<(std::ostream&, const Constraint&)'
  graphviz-2.40.1/lib/vpsc/constraint.cpp:46:7: warning: the compiler can assume that the address of 'c' will never be NULL [-Waddress]
  #  if(&c==NULL) {
  #       ^
  #   44|   std::ostream& operator <<(std::ostream &os, const Constraint &c)
  #   45|   {
  #   46|->   if(&c==NULL) {
  #   47|       os<<"NULL";
  #   48|     } else {

Related to #1464.

lib/vpsc/constraint.cpp

index 10fa5b485383fea2d646f7aae266a061027c5b8c..e3561a088d85b1bfcf4a01876e0fd468d1c5e20a 100644 (file)
@@ -43,10 +43,6 @@ Constraint::~Constraint() {
 }
 std::ostream& operator <<(std::ostream &os, const Constraint &c)
 {
-       if(&c==NULL) {
-               os<<"NULL";
-       } else {
-               os<<*c.left<<"+"<<c.gap<<"<="<<*c.right<<"("<<c.slack()<<")"<<(c.active?"-active":"");
-       }
+       os<<*c.left<<"+"<<c.gap<<"<="<<*c.right<<"("<<c.slack()<<")"<<(c.active?"-active":"");
        return os;
 }