Fix a segfault in state-script handling