Skip to content

Commit

Permalink
fix(cellOverflow): Create deep copies of the state
Browse files Browse the repository at this point in the history
  • Loading branch information
jubnzv committed Nov 19, 2024
1 parent 6f3b112 commit 2998552
Showing 1 changed file with 25 additions and 9 deletions.
34 changes: 25 additions & 9 deletions src/detectors/builtin/cellUnderflow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,16 +233,32 @@ class CellUnderflowTransfer implements Transfer<CellUnderflowState> {
_node: BasicBlock,
stmt: AstStatement,
): CellUnderflowState {
const outState = {
builders: new Map(inState.builders),
cells: new Map(inState.cells),
slices: new Map(inState.slices),
messages: new Map(inState.messages),
structs: new Map(inState.structs),
intermediateVariables: [...inState.intermediateVariables],
const copyVarMap = <K>(map: Map<K, Variable>): Map<K, Variable> =>
new Map(
Array.from(map).map(([k, v]) => [
k,
{ ...v, storage: deepCopyVariableStorage(v.storage) },
]),
);
const copyVarArray = <T extends { storage: VariableStorage }>(
arr: T[],
): T[] =>
arr.map(
(v) => ({ ...v, storage: deepCopyVariableStorage(v.storage) }) as T,
);

// Create deep copy of state
const out = {
builders: copyVarMap(inState.builders),
cells: copyVarMap(inState.cells),
slices: copyVarMap(inState.slices),
messages: copyVarMap(inState.messages),
structs: copyVarMap(inState.structs),
intermediateVariables: copyVarArray(inState.intermediateVariables),
};
this.processStatement(outState, stmt);
return outState;

this.processStatement(out, stmt);
return out;
}

/**
Expand Down

0 comments on commit 2998552

Please sign in to comment.