From fcb8bf57c661316bbcf581a1bcac99d283529c59 Mon Sep 17 00:00:00 2001 From: "Darryl L. Miles" Date: Fri, 4 Oct 2024 20:09:28 +0100 Subject: [PATCH] ext2spice.c: pname used before initialization In order for pname to be assigned a value the loop must have performed an interation. The order of assignment and use of 'pname' is not the natural order you'd expect. It also looks like the TxPrint message may display the incorrect port name from the previous loop iteration. The code block looks like the resolution of 'pname' has no side-effects. So should be done first so the correct port name is output in the log message. SonarCloud 2nd function call argument is an uninitialized value https://sonarcloud.io/project/issues?open=AZJB17lqNGfDNup0Rk6f&id=dlmiles_magic --- ext2spice/ext2spice.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ext2spice/ext2spice.c b/ext2spice/ext2spice.c index 5a53690e..e4943e89 100644 --- a/ext2spice/ext2spice.c +++ b/ext2spice/ext2spice.c @@ -1885,14 +1885,6 @@ topVisit(def, doStub) else heh = HashLookOnly(&efNodeHashTable, (char *)snode->efnode_name->efnn_hier); - if (heh == (HashEntry *)NULL) - { - /* Port was optimized out */ - snode->efnode_flags &= ~EF_PORT; - TxPrintf("Note: Port %s was optimized out of %s\n", - pname, def->def_name); - continue; - } /* If view is abstract, rely on the given port name, not * the node. Otherwise, artifacts of the abstract view @@ -1908,6 +1900,15 @@ topVisit(def, doStub) // pname = nodeSpiceName(snode->efnode_name->efnn_hier, NULL); pname = nodeSpiceName(nodeName->efnn_hier, NULL); + if (heh == (HashEntry *)NULL) /* pname now resolved for log output */ + { + /* Port was optimized out */ + snode->efnode_flags &= ~EF_PORT; + TxPrintf("Note: Port %s was optimized out of %s\n", + pname, def->def_name); + continue; + } + hep = HashLookOnly(&portNameTable, pname); if (hep == (HashEntry *)NULL) {