]> sigrok.org Git - libsigrokdecode.git/commitdiff
avr_isp: fix crash if part name is not known
authorSimon Ruderich <redacted>
Thu, 8 Feb 2024 23:21:23 +0000 (00:21 +0100)
committerSoeren Apel <redacted>
Tue, 27 Feb 2024 19:26:53 +0000 (20:26 +0100)
Decoding an unknown part causes a KeyError exception. For example for an
ATmega328/P:

    srd: KeyError: Calling avr_isp-1 decode() failed: (149, 15)

decoders/avr_isp/pd.py

index e3af4d6f0b8b9219483f72074093678a01711d42..9e3c5df12a7e824c11037ca401237b4d156422e5 100644 (file)
@@ -123,9 +123,12 @@ class Decoder(srd.Decoder):
         self.part_number = ret[3]
         self.putx([Ann.RSB2, ['Part number: 0x%02x' % ret[3]]])
 
-        p = part[(self.part_fam_flash_size, self.part_number)]
-        data = [Ann.DEV, ['Device: Atmel %s' % p]]
-        self.put(self.ss_device, self.es_cmd, self.out_ann, data)
+        # Part name if known
+        key = (self.part_fam_flash_size, self.part_number)
+        if key in part:
+            p = part[key]
+            data = [Ann.DEV, ['Device: Atmel %s' % p]]
+            self.put(self.ss_device, self.es_cmd, self.out_ann, data)
 
         # Sanity check on reply.
         if ret[1] != 0x30 or ret[2] != self.xx or ret[0] != self.mm: