commit e45801db8b29a92723d0f2ea0a1a1a77f3cc7d47
parent e94025758a20cf19557cefc0cc13cf91382edfcf
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Sat, 4 Jan 2025 00:24:30 +0100
cc2: Preserve value of curstmt in apply()
As the function pointers are allowed to add new statements we have to
preserve the value of curstmt in case the function returns NULL that
should affect to the value of curstmt before calling the function,
and not to the new state populated by the function.
Diffstat:
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/src/cmd/scc-cc/cc2/node.c b/src/cmd/scc-cc/cc2/node.c
@@ -172,10 +172,11 @@ delrange(Node *begin, Node *end)
void
apply(Node *(*fun)(Node *))
{
- Node *np;
+ Node *np, *ocurstmt;
for (curstmt = curfun->u.stmt; curstmt; curstmt = np) {
+ ocurstmt = curstmt;
np = (*fun)(curstmt);
- np = (np) ? np->next : delstmt(curstmt);
+ np = (np) ? np->next : delstmt(ocurstmt);
}
}