diff options
| author | Cliff Click <cliffc@acm.org> | 2024-09-30 09:15:12 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2024-10-06 08:56:22 -0700 |
| commit | 45ab4741a5ace18e77b027a2f7e318327c33d4b7 (patch) | |
| tree | 3ef67cd27b512fc9832f02f2df48d8ce4cec43a8 /chapter15/src/main/java/com/seaofnodes | |
| parent | 31ba4ecbc5214b3c25917fd97d030bfd39a784a3 (diff) | |
| download | Simple-45ab4741a5ace18e77b027a2f7e318327c33d4b7.tar.gz Simple-45ab4741a5ace18e77b027a2f7e318327c33d4b7.zip | |
Tests for negative array size and runtime OOB
Diffstat (limited to 'chapter15/src/main/java/com/seaofnodes')
| -rw-r--r-- | chapter15/src/main/java/com/seaofnodes/simple/Parser.java | 2 | ||||
| -rw-r--r-- | chapter15/src/main/java/com/seaofnodes/simple/node/ReturnNode.java | 3 |
2 files changed, 4 insertions, 1 deletions
diff --git a/chapter15/src/main/java/com/seaofnodes/simple/Parser.java b/chapter15/src/main/java/com/seaofnodes/simple/Parser.java index d9726d28..ec040b4f 100644 --- a/chapter15/src/main/java/com/seaofnodes/simple/Parser.java +++ b/chapter15/src/main/java/com/seaofnodes/simple/Parser.java @@ -711,6 +711,8 @@ public class Parser { private Node newArray(Type t) { Node len = parseExpression().keep(); + if( !(len._type instanceof TypeInteger) ) + throw error("Cannot allocate an array with length "+len._type); TypeStruct ary = (TypeStruct)TYPES.get("[]"+t.str()); if( ary == null ) { TYPES.put("[]"+t.str(), ary = TypeStruct.makeAry(TypeInteger.BOT,ALIAS++,t,ALIAS++)); diff --git a/chapter15/src/main/java/com/seaofnodes/simple/node/ReturnNode.java b/chapter15/src/main/java/com/seaofnodes/simple/node/ReturnNode.java index 444b76a8..e12f1fef 100644 --- a/chapter15/src/main/java/com/seaofnodes/simple/node/ReturnNode.java +++ b/chapter15/src/main/java/com/seaofnodes/simple/node/ReturnNode.java @@ -17,7 +17,8 @@ public class ReturnNode extends CFGNode { public ReturnNode(Node ctrl, Node data, ScopeNode scope) { super(ctrl, data); - // We lookup memory slices by the naming convention that they start with $ + // Add memory slices to Return, so all memory updates are live-on-exit. + // We look up memory slices by the naming convention that they start with $. // We could also use implicit knowledge that all memory projects are at offset >= 2 if( scope != null ) { String[] names = scope.reverseNames(); |
