Skip to content

Commit b212588

Browse files
committed
prepack.cpp: corrected segfault issue with last_block
Signed-off-by: Alessandro Comodi <[email protected]>
1 parent 6b26296 commit b212588

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

vpr/src/pack/prepack.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -881,7 +881,16 @@ t_pack_molecule *alloc_and_load_pack_molecules(
881881
/* try_pack_molecule function can pack more than one atom */
882882
/* check if we packed last atom of a chain */
883883
int num_blocks = cur_molecule->num_blocks;
884-
auto last_block = cur_molecule->atom_block_ids[num_blocks-1];
884+
885+
/* Getting the last valid block of a molecule */
886+
auto last_block = AtomBlockId::INVALID();
887+
for (int i = 0; i < num_blocks; i++) {
888+
auto tmp_last_block = cur_molecule->atom_block_ids[i];
889+
if (tmp_last_block != AtomBlockId::INVALID())
890+
last_block = tmp_last_block;
891+
else
892+
break;
893+
}
885894

886895
/* Getting the next blk_id in the chain. If there is not the chain is completed */
887896
blk_id = AtomBlockId::INVALID();

0 commit comments

Comments
 (0)