From e19893ac3218e6cb4c517109811edc5b8b4a0c0f Mon Sep 17 00:00:00 2001 From: Jean-Paul Chaput Date: Sat, 6 Aug 2016 18:19:22 +0200 Subject: [PATCH] Fix divide by zero in GCells of null size. * Bug: In Anabatic::GCell, when width and/or heigh is null, do not try to compute densities as it will trigger a divide by zero (and do not make much sense anyway). * Change: In CRL Core, in cmos/alliance.conf, honor the ALLIANCE_TOP variable if it is found in the user's environement. --- anabatic/src/GCell.cpp | 29 ++++++++++++++++++++++------- anabatic/src/Session.cpp | 9 ++------- crlcore/etc/cmos/alliance.conf | 2 +- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/anabatic/src/GCell.cpp b/anabatic/src/GCell.cpp index ad5274a7..5446b334 100644 --- a/anabatic/src/GCell.cpp +++ b/anabatic/src/GCell.cpp @@ -1417,21 +1417,36 @@ namespace Anabatic { for ( size_t i=0 ; i<_depth ; i++ ) { switch ( Session::getDirection(i) ) { case Flags::Horizontal: - _densities [i] = ((float)uLengths2[i]) / ( hcapacity * (float)width ); - _feedthroughs [i] += (float)(_blockages[i] / width); - _fragmentations[i] = (float)ufragments[i].getMaxFree().getSize() / (float)width; + if (width) { + _densities [i] = ((float)uLengths2[i]) / ( hcapacity * (float)width ); + _feedthroughs [i] += (float)(_blockages[i] / width); + _fragmentations[i] = (float)ufragments[i].getMaxFree().getSize() / (float)width; + } else { + _densities [i] = 0; + _feedthroughs [i] = 0; + _fragmentations[i] = 0; + } break; case Flags::Vertical: - _densities [i] = ((float)uLengths2[i]) / ( vcapacity * (float)height ); - _feedthroughs [i] += (float)(_blockages[i] / height); - _fragmentations[i] = (float)ufragments[i].getMaxFree().getSize() / (float)height; + if (height) { + _densities [i] = ((float)uLengths2[i]) / ( vcapacity * (float)height ); + _feedthroughs [i] += (float)(_blockages[i] / height); + _fragmentations[i] = (float)ufragments[i].getMaxFree().getSize() / (float)height; + } else { + _densities [i] = 0; + _feedthroughs [i] = 0; + _fragmentations[i] = 0; + } break; } if (_densities[i] >= 1.0) _flags |= Flags::Saturated; } - _cDensity = ( (float)_contacts.size() ) / ccapacity; + if (ccapacity) + _cDensity = ( (float)_contacts.size() ) / ccapacity; + else + _cDensity = 0; _flags.reset( Flags::Invalidated ); checkDensity(); diff --git a/anabatic/src/Session.cpp b/anabatic/src/Session.cpp index bdb7657d..1849eefe 100644 --- a/anabatic/src/Session.cpp +++ b/anabatic/src/Session.cpp @@ -32,13 +32,8 @@ namespace { - const char* reopenSession = - "Session::open() :\n\n" - " Session already open for %s (internal error)."; - - const char* openSessionError = - "%s :\n\n" - " Session has not been opened (internal error)."; + const char* reopenSession = "Session::open(): Session already open for %s (internal error)."; + const char* openSessionError = "%s: Session has not been opened (internal error)."; } // End of local namespace. diff --git a/crlcore/etc/cmos/alliance.conf b/crlcore/etc/cmos/alliance.conf index 6aa44284..b763f2ee 100644 --- a/crlcore/etc/cmos/alliance.conf +++ b/crlcore/etc/cmos/alliance.conf @@ -6,7 +6,7 @@ from helpers.Alliance import Gauge allianceTop = None -if os.environ.has_key['ALLIANCE_TOP']: +if os.environ.has_key('ALLIANCE_TOP'): allianceTop = os.environ['ALLIANCE_TOP'] if not os.path.isdir(allianceTop): allianceTop = None