]> www.infradead.org Git - users/dwmw2/openconnect.git/commitdiff
Fix DeepSource alert
authorDimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
Fri, 24 Sep 2021 17:33:11 +0000 (19:33 +0200)
committerDimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
Fri, 24 Sep 2021 17:52:36 +0000 (19:52 +0200)
Built-in function `len` used as condition

Using the `len` function to check if a sequence is empty is not idiomatic
and can be less performant than checking the truthiness of the object.

`len` doesn't know the context in which it is called, so if computing the
length means traversing the entire sequence, it must; it doesn't know
that the result is just being compared to 0. Computing the boolean value
can stop after it sees the first element, regardless of how long the
sequence actually is.

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
trojans/tncc-emulate.py

index 338aaa175bcdd2408e0490ddddde1b90f321139c..b6f2093d8bc1c4096dcf971370ceaba25d1652b2 100755 (executable)
@@ -353,7 +353,7 @@ class tncc(object):
         for line in self.r.readlines():
             line = line.strip().decode()
             # Note that msg is too long and gets wrapped, handle it special
-            if last_key == 'msg' and len(line):
+            if last_key == 'msg' and line:
                 response['msg'] += line
             else:
                 key = ''
@@ -620,14 +620,14 @@ class tncc_server(object):
 
     def process_cmd(self):
         buf = self.sock.recv(1024).decode('ascii')
-        if not len(buf):
+        if not buf:
             sys.exit(0)
         cmd, buf = buf.split('\n', 1)
         cmd = cmd.strip()
         args = dict()
         for n in buf.split('\n'):
             n = n.strip()
-            if len(n):
+            if n:
                 key, val = n.strip().split('=', 1)
                 args[key] = val
         if cmd == 'start':