Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove bignum check from save_history #1018

Merged
merged 1 commit into from
Oct 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 3 additions & 12 deletions lib/irb/history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ module History
class << self
# Integer representation of <code>IRB.conf[:HISTORY_FILE]</code>.
def save_history
num = IRB.conf[:SAVE_HISTORY].to_i
# Bignums cause RangeErrors when slicing arrays.
# Treat such values as 'infinite'.
(num > save_history_max) ? -1 : num
IRB.conf[:SAVE_HISTORY].to_i
end

def save_history?
Expand All @@ -27,13 +24,6 @@ def history_file
IRB.rc_file("_history")
end
end

private

def save_history_max
# Max fixnum (32-bit) that can be used without getting RangeError.
2**30 - 1
end
end
end

Expand Down Expand Up @@ -90,7 +80,8 @@ def save_history
hist = history.map { |l| l.scrub.split("\n").join("\\\n") }

unless append_history || History.infinite?
hist = hist.last(History.save_history)
# Check size before slicing because array.last(huge_number) raises RangeError.
hist = hist.last(History.save_history) if hist.size > History.save_history
end

f.puts(hist)
Expand Down
Loading