[tor-commits] [stem/master] Optimize error check for non-negative inputs

atagar at torproject.org atagar at torproject.org
Sun Aug 26 20:49:21 UTC 2018


commit 71bb7d5e42125f2d89c8dddc56fa16c71989c5cd
Author: Dave Rolek <dmr-x at riseup.net>
Date:   Tue Aug 7 18:32:31 2018 +0000

    Optimize error check for non-negative inputs
    
    stem.client presently makes typical use of non-negative inputs with
    unsigned types.
---
 stem/client/datatype.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/stem/client/datatype.py b/stem/client/datatype.py
index e19adfb1..1c7aec77 100644
--- a/stem/client/datatype.py
+++ b/stem/client/datatype.py
@@ -358,7 +358,7 @@ class Size(Field):
   def pack(self, content):
     if not stem.util._is_int(content):
       raise ValueError('Size.pack encodes an integer, but was a %s' % type(content).__name__)
-    if self.unsigned and content < 0:
+    if content < 0 and self.unsigned:
       raise ValueError('A %s field cannot pack negative values, but %i was tried' % (self.name, content))
 
     packed = struct.pack(self.format, content)





More information about the tor-commits mailing list