Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/topic/robin/gh-1871-max-size'
Browse files Browse the repository at this point in the history
* origin/topic/robin/gh-1871-max-size:
  Fix `&max-size` on unit containing a `switch`.
  • Loading branch information
rsmmr committed Oct 15, 2024
2 parents e6cb813 + 3825ff9 commit ab69192
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
1.12.0-dev.140 | 2024-10-15 16:21:58 +0200

* GH-1871: Fix `&max-size` on unit containing a `switch`. (Robin Sommer, Corelight)

We would advance our input too early, letting the subsequent
`&max-size` check fail.

1.12.0-dev.138 | 2024-10-14 16:16:08 +0200

* GH-1868: Associate source code locations with current fiber instead of current thread. (Robin Sommer, Corelight)
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.12.0-dev.138
1.12.0-dev.140
7 changes: 1 addition & 6 deletions spicy/toolchain/src/compiler/codegen/parser-builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -715,13 +715,8 @@ struct ProductionVisitor : public production::Visitor {
stop = pb->newContainerItem(*meta.container(), destination(), elem, ! meta.container()->isTransient());
}

else if ( ! meta.isFieldProduction() ) {
// Need to move position ahead.
if ( state().ncur )
builder()->addAssign(state().cur, state().ncur);

else if ( ! meta.isFieldProduction() )
popDestination();
}

else if ( field->parseType()->type()->isA<hilti::type::Void>() )
popDestination();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
[error] terminating with uncaught exception of type spicy::rt::ParseError: parsing not done within &max-size bytes (<...>/max-size-with-switch-fail.spicy:12:3-12:13)
12 changes: 12 additions & 0 deletions tests/spicy/types/unit/max-size-with-switch-fail.spicy
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# @TEST-EXEC-FAIL: printf 12345 | spicy-driver -d %INPUT >output 2>&1
# @TEST-EXEC: btest-diff output
#
# @TEST-DOC: Switch clause with a &max-size attribute exceeded by our input

module foo;

public type X = unit {
switch (0) {
* -> : bytes &eod;
};
} &max-size=3;
11 changes: 11 additions & 0 deletions tests/spicy/types/unit/max-size-with-switch.spicy
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# @TEST-EXEC: echo -n | spicy-driver -d %INPUT
#
# @TEST-DOC: Switch clause with a &max-size attribute never reached; regression test for #1871

module foo;

public type X = unit {
switch (0) {
* -> : void;
};
} &max-size=4711; # Should never fail as unit consumes zero bytes.

0 comments on commit ab69192

Please sign in to comment.