Don't generate tree names longer than the max supported.

Fixes #741