could it be a fourth output parameter to this function, rather than a non-obvious side-effect?