Skip to content

Commit

Permalink
Add check for int64->int conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
antonmedv committed Sep 6, 2023
1 parent 1894b2a commit 2683a94
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package parser

import (
"fmt"
"math"
"strconv"
"strings"

Expand Down Expand Up @@ -310,6 +311,10 @@ func (p *parser) parseSecondary() Node {
if err != nil {
p.error("invalid hex literal: %v", err)
}
if number > math.MaxInt {
p.error("integer literal is too large")
return nil
}
node := &IntegerNode{Value: int(number)}
node.SetLocation(token.Location)
return node
Expand All @@ -326,6 +331,10 @@ func (p *parser) parseSecondary() Node {
if err != nil {
p.error("invalid integer literal: %v", err)
}
if number > math.MaxInt {
p.error("integer literal is too large")
return nil
}
node := &IntegerNode{Value: int(number)}
node.SetLocation(token.Location)
return node
Expand Down

0 comments on commit 2683a94

Please sign in to comment.