HeapScanDescData->rs_cindex (the current index into the array of visible tuples stored in the heap scan descriptor) is used for multiple scan types, but for bitmap heap scans, AFAICT, it should never be < 0.
As such, I find this test in heapam_scan_bitmap_next_tuple() pretty confusing.
if (hscan->rs_cindex < 0 || hscan->rs_cindex >= hscan->rs_ntuples)
I know it seems innocuous, but I find it pretty distracting. Am I missing something? Could it somehow be < 0?
If not, I propose removing that part of the if statement like in the attached patch.
You are right it can never be < 0 in this case at least. In fact you don't need to explicitly set it to 0 in initscan[1], because before calling heapam_scan_bitmap_next_tuple() we must call heapam_scan_bitmap_next_block() and this function is initializing this to 0 (hscan->rs_cindex = 0;). Anyway no object even if you prefer to initialize in initscan(), just the point is that we are already doing it for each block before fetching tuples from the block.