Skip to content

Commit

Permalink
fix: allow larger jumps in hex patterns.
Browse files Browse the repository at this point in the history
The limit was 65535 because 16-bits integers were used for storing the jump ranges. Now we are using 32-bits integers.

Closes #238
  • Loading branch information
plusvic committed Nov 11, 2024
1 parent 03e9810 commit 1e6b6c7
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lib/src/compiler/ir/hex2hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,8 @@ fn hex_sub_pattern_hir_from_ast(
}

hir_tokens.push(hir::Hir::repetition(hir::Repetition {
min: jump.start.map(|start| start as u32).unwrap_or(0),
max: jump.end.map(|end| end as u32),
min: jump.start.unwrap_or(0),
max: jump.end,
greedy: false,
sub: Box::new(hir::Hir::dot(hir::Dot::AnyByte)),
}))
Expand Down
2 changes: 1 addition & 1 deletion lib/src/compiler/tests/testdata/errors/101.in
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
rule test {
strings:
$a = { 11 [0-65536] 22 }
$a = { 11 [0-4294967296] 22 }
condition:
$a
}
4 changes: 2 additions & 2 deletions lib/src/compiler/tests/testdata/errors/101.out
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
error[E027]: invalid integer
--> line:3:18
|
3 | $a = { 11 [0-65536] 22 }
| ^^^^^ this number is out of the valid range: [0, 65535]
3 | $a = { 11 [0-4294967296] 22 }
| ^^^^^^^^^^ this number is out of the valid range: [0, 4294967295]
|
4 changes: 2 additions & 2 deletions parser/src/ast/cst2ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -851,14 +851,14 @@ impl<'src> Builder<'src> {
let mut end = None;

if let Event::Token { kind: INTEGER_LIT, .. } = self.peek() {
let (value, _lit, _span) = self.integer_lit::<u16>()?;
let (value, _lit, _span) = self.integer_lit::<u32>()?;
start = Some(value);
};

if let Event::Token { kind: HYPHEN, .. } = self.peek() {
self.expect(HYPHEN)?;
if let Event::Token { kind: INTEGER_LIT, .. } = self.peek() {
let (value, _lit, _span) = self.integer_lit::<u16>()?;
let (value, _lit, _span) = self.integer_lit::<u32>()?;
end = Some(value);
};
} else {
Expand Down
6 changes: 3 additions & 3 deletions parser/src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,13 @@ impl HexAlternative {
#[derive(Debug, Clone, Default)]
pub struct HexJump {
span: Span,
pub start: Option<u16>,
pub end: Option<u16>,
pub start: Option<u32>,
pub end: Option<u32>,
}

impl HexJump {
#[doc(hidden)]
pub fn new(start: Option<u16>, end: Option<u16>) -> Self {
pub fn new(start: Option<u32>, end: Option<u32>) -> Self {
Self { start, end, span: Span::default() }
}
}
Expand Down

0 comments on commit 1e6b6c7

Please sign in to comment.