laforge has uploaded this change for review.

View Change

osmocom.construct.PaddedBcdAdapter: Support zero-length strings

We cannot use the [-1] slicing if the input string has zero length.

Fix typo in docstring while we're touching that class anyway.

Change-Id: Ib5afb5ab5c2bc9b519dc92818fc6974f7eecba16
---
M src/osmocom/construct.py
1 file changed, 2 insertions(+), 2 deletions(-)

git pull ssh://gerrit.osmocom.org:29418/python/pyosmocom refs/changes/31/41731/1
diff --git a/src/osmocom/construct.py b/src/osmocom/construct.py
index d369bc7..548f22d 100644
--- a/src/osmocom/construct.py
+++ b/src/osmocom/construct.py
@@ -262,11 +262,11 @@
return h2b(swap_nibbles(obj))

class PaddedBcdAdapter(BcdAdapter):
- """Representatin of a BCD string of potentially odd number of BCD digits,
+ """Representation of a BCD string of potentially odd number of BCD digits,
which then need to be padded at the end with an 'f' nibble."""
def _decode(self, obj, context, path):
r = super()._decode(obj, context, path)
- if r[-1] == 'f':
+ if len(r) >= 1 and r[-1] == 'f':
return r[:-1]
else:
return r

To view, visit change 41731. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: python/pyosmocom
Gerrit-Branch: master
Gerrit-Change-Id: Ib5afb5ab5c2bc9b519dc92818fc6974f7eecba16
Gerrit-Change-Number: 41731
Gerrit-PatchSet: 1
Gerrit-Owner: laforge <laforge@osmocom.org>