rainbow icon indicating copy to clipboard operation
rainbow copied to clipboard

Fix remove_hooks dict iteration

Open erdnaxe opened this issue 10 months ago • 2 comments

When running tests, the following error is raised:

    def remove_hooks(self):
        """Remove all hooked functions."""
>       for addr, hook in self.stubbed_functions.items():
E       RuntimeError: dictionary changed size during iteration

This is caused by https://github.com/Ledger-Donjon/rainbow/pull/65 (oops).

This PR proposes a trivial patch to fix the issue. With this PR, all tests are now green 🎉

erdnaxe avatar Jun 09 '25 08:06 erdnaxe

Hello, Wouldn't it be easier to restore self.stubbed_functions = {}?

    def remove_hooks(self):
        """Remove all hooked functions."""
        for hook in self.stubbed_functions.values():
            self.emu.hook_del(hook)
        self.stubbed_functions = {}

(or to use dict.clear?)

niooss-ledger avatar Jun 10 '25 13:06 niooss-ledger

Thanks for the review! I updated the patch with .clear() which seems cleaner.

erdnaxe avatar Jun 12 '25 08:06 erdnaxe