Fix pointer comparisons, and add a test for it.