treesearch: avoid division by zero