I finally pushed this fix. In the end I both relaxed the assert a little bit to allow calling build_distances for a single range, and added a bail out so that the caller gets regular NULL and not whatever palloc(0) produces.
Thanks again for the report! regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company