diff options
author | Sebastian Koslowski <koslowski@kit.edu> | 2013-11-25 22:52:32 +0100 |
---|---|---|
committer | Sebastian Koslowski <koslowski@kit.edu> | 2013-11-29 12:37:12 +0100 |
commit | 549b060f2d8f7636cd7f9053e93eb279e93c662a (patch) | |
tree | ebe28bc89e4f8155d6a7a10a5838e519f7a5e2c7 /grc/python/Port.py | |
parent | ce4f279d84b0d7e64114da75a0abe669fb4c7c97 (diff) |
grc: fixes undefined behavior in get_nports() (WIP)
Diffstat (limited to 'grc/python/Port.py')
-rw-r--r-- | grc/python/Port.py | 8 |
1 files changed, 4 insertions, 4 deletions
diff --git a/grc/python/Port.py b/grc/python/Port.py index c7b802a23c..5f1247ce45 100644 --- a/grc/python/Port.py +++ b/grc/python/Port.py @@ -177,7 +177,7 @@ class Port(_Port, _GUIPort): """ Get the number of ports. If already blank, return a blank - If the evaluation of nports cannot be cast to an integer, return 1. + If the evaluation of nports cannot be cast to a positive integer, return 1. Returns: the number of ports or 1 @@ -186,9 +186,9 @@ class Port(_Port, _GUIPort): #return blank if nports is blank if not nports: return '' try: - nports = int(self.get_parent().get_parent().evaluate(nports)) - if 0 < nports: return nports - except: return 1 + return max(1, int(self.get_parent().get_parent().evaluate(nports))) + except: + return 1 def get_optional(self): return bool(self._optional) |