Fix #5483

Seems straightforward enough, but since this is a critical code path, someone should double-check.