From b8c350b3e4d0a6f278a26ed8e1358dac298ba920 Mon Sep 17 00:00:00 2001 From: jdavidberger Date: Thu, 2 Apr 2026 12:53:07 -0600 Subject: [PATCH] Update pack.cc (#1685) This fixes a memory issue. When you assign to base_iodelay_rules from itself, the LHS when you do `base_iodelay_rules[id_DELAYA] = base_iodelay_rules[id_DELAYB]`, can cause a heap allocation which possibly invalidates the memory of the RHS. This was found while running nextpnr under ASAN. It might be useful to add testing under libasan into CI. --- nexus/pack.cc | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/nexus/pack.cc b/nexus/pack.cc index b02d25c6..616da530 100644 --- a/nexus/pack.cc +++ b/nexus/pack.cc @@ -1232,10 +1232,12 @@ struct NexusPacker dict base_iodelay_rules; base_iodelay_rules[id_DELAYB].new_type = id_IOLOGIC; - base_iodelay_rules[id_DELAYB].param_xform[id_DEL_VALUE] = ctx->id("DELAY.DEL_VALUE"); - base_iodelay_rules[id_DELAYB].param_xform[id_COARSE_DELAY] = ctx->id("DELAY.COARSE_DELAY"); - - base_iodelay_rules[id_DELAYA] = base_iodelay_rules[id_DELAYB]; + XFormRule delay_rule; + delay_rule.param_xform[id_DEL_VALUE] = ctx->id("DELAY.DEL_VALUE"); + delay_rule.param_xform[id_COARSE_DELAY] = ctx->id("DELAY.COARSE_DELAY"); + + base_iodelay_rules[id_DELAYB] = delay_rule; + base_iodelay_rules[id_DELAYA] = delay_rule; base_iodelay_rules[id_DELAYA].param_xform[id_COARSE_DELAY_MODE] = ctx->id("DELAY.COARSE_DELAY_MODE"); base_iodelay_rules[id_DELAYA].param_xform[id_EDGE_MONITOR] = ctx->id("DELAY.EDGE_MONITOR");