ScratchABit icon indicating copy to clipboard operation
ScratchABit copied to clipboard

Out-of-range functions

Open thesourcerer8 opened this issue 6 years ago • 1 comments

The automatic function detection seems to register also functions that are outside the valid areas. This causes errors when saving the file afterwards:

Traceback (most recent call last):
  File "./ScratchABit.py", line 1032, in <module>
    saveload.save_state(project_dir)
  File "/home/user/scratch/ScratchABit/scratchabit/saveload.py", line 32, in save_state
    engine.ADDRESS_SPACE.save_addr_props(project_dir + "/project.aprops")
  File "/home/user/scratch/ScratchABit/scratchabit/engine.py", line 683, in save_addr_props
    while addr > areas[area_i][END]:
IndexError: list index out of range

The following patch logs the offending function definition:

--- a/scratchabit/engine.py
+++ b/scratchabit/engine.py
@@ -680,8 +680,11 @@ class AddressSpace:
             if addr > area_end:
                 stream.close()
                 area_i += 1
-                while addr > areas[area_i][END]:
+                while area_i<len(areas) and addr > areas[area_i][END]:
                     area_i += 1
+                if area_i>=len(areas):
+                    log.debug("addr not valid (%x,%s)", addr, props.get("label"))
+                assert area_i<len(areas)

thesourcerer8 avatar Jan 25 '18 13:01 thesourcerer8

I believe this should be fixed by https://github.com/pfalcon/ScratchABit/commit/93b1e217f208d955a39259e95bd528d78c4dff4d

pfalcon avatar Jan 27 '18 18:01 pfalcon