From 549b060f2d8f7636cd7f9053e93eb279e93c662a Mon Sep 17 00:00:00 2001
From: Sebastian Koslowski <koslowski@kit.edu>
Date: Mon, 25 Nov 2013 22:52:32 +0100
Subject: grc: fixes undefined behavior in get_nports() (WIP)

---
 grc/python/Port.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

(limited to 'grc/python/Port.py')

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)
 
-- 
cgit v1.2.3