Whole file
eerimoq/bincopy
The author described this change as “Fix: issue 4: Intel hex bad addresses”. It counts as a record because the check below fails on the code as it stood at e26a28166 and passes on c420fb248, with nothing else changed between the two runs.
Projecteerimoq/bincopy
Fix saved2016-06-01
Sharing licenceMIT · LICENSE
Change size+14 −6
What the code was meant to do, written into the code itself as a save note
Fix: issue 4: Intel hex bad addresses
The change
| 8 | 8 | import string | |
| 9 | 9 | ||
| 10 | 10 | __author__ = 'Erik Moqvist' | |
| 11 | - | __version__ = '2.1.1' | |
| 11 | + | __version__ = '2.1.2' | |
| 12 | 12 | ||
| 13 | 13 | DEFAULT_WORD_SIZE = 8 | |
| 14 | 14 | ||
| ⋯ | |||
| 220 | 220 | self.list = [] | |
| 221 | 221 | ||
| 222 | 222 | def add(self, segment): | |
| 223 | + | """Add segments by ascending address. | |
| 224 | + | ||
| 225 | + | """ | |
| 226 | + | ||
| 223 | 227 | if self.list: | |
| 224 | 228 | if segment.minimum == self.current_segment.maximum: | |
| 225 | 229 | # fast insertion for adjecent segments | |
| ⋯ | |||
| 446 | 450 | """ | |
| 447 | 451 | ||
| 448 | 452 | data_address = [] | |
| 449 | - | extmaximumed_address = -1 | |
| 453 | + | extended_linear_address = 0 | |
| 450 | 454 | ||
| 451 | 455 | for address, data in self.segments.iter(size): | |
| 452 | 456 | address //= self.word_size_bytes | |
| 457 | + | address_upper_16_bits = (address >> 16) | |
| 458 | + | address_lower_16_bits = (address & 0xffff) | |
| 453 | 459 | ||
| 454 | 460 | if address_length == 32: | |
| 455 | - | if ((address >> 16) & 0xffff) > extmaximumed_address: | |
| 456 | - | extmaximumed_address = ((address >> 16) & 0xffff) | |
| 461 | + | # All segments are sorted by address. Update the | |
| 462 | + | # extended linear address when required. | |
| 463 | + | if address_upper_16_bits > extended_linear_address: | |
| 464 | + | extended_linear_address = address_upper_16_bits | |
| 457 | 465 | packed = pack_ihex(4, | |
| 458 | 466 | 0, | |
| 459 | 467 | 2, | |
| 460 | 468 | binascii.unhexlify('%04X' | |
| 461 | - | % extmaximumed_address)) | |
| 469 | + | % extended_linear_address)) | |
| 462 | 470 | data_address.append(packed) | |
| 463 | 471 | else: | |
| 464 | 472 | raise Error('unsupported address length %d' | |
| 465 | 473 | % address_length) | |
| 466 | 474 | ||
| 467 | - | data_address.append(pack_ihex(0, address, len(data), data)) | |
| 475 | + | data_address.append(pack_ihex(0, address_lower_16_bits, len(data), data)) | |
| 468 | 476 | ||
| 469 | 477 | footer = [] | |
| 470 | 478 | ||
The check that tells the two apart
fail→pass·tests/test_bincopy.py::BinCopyTest::test_issue_4
Check file tests/test_bincopy.py, taken without changes from the fix and copied onto the older code, so the exact same check runs against both versions.
Origin and history
The code before ite26a28166573c1c99fba648a148657b3d09e728d
Broken version dated2016-05-01
Modulebincopy
Units changedFile, _Segments
Fingerprint95641a7968d696c4
Checked2026-08-18 by goldset/0.1
Every field above is generated by our program. None of it is written by hand.