When sharing scripts that are likely to be run by regular users, I strongly recommend performing some kind of camera model / firmware version checking. CHDK do this for scripts meant to be run by users (look up "check_compat").
Most of the time, the effect of calling an invalid stub - which would usually jump in the middle of some random Canon function - will be a crash, but if one is unlucky enough, that crash might lead to a memory write that will end up written back into main ROM at camera shutdown (
yes, Canon firmware does this). Or, what if - on some different camera model - that stub might be in the middle of EraseSectorOfRom? Very unlikely, but still...
I've got a fair amount of backlash in the past for recommending
this timeless article to other developers, but I still believe the advice there is very good (
long answer). And I have no experience unbricking recent Canon models, btw
