Fix UB when generating local indices for constraints