summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authoraycabta <aycabta@gmail.com>2020-08-07 23:42:51 +0900
committeraycabta <aycabta@gmail.com>2020-08-18 14:38:01 +0900
commitef498a016b496c20e45dfeaa3064f8033f420336 (patch)
tree40f7b401ad8bb48497ab79b71e44ccc4910a487c /lib
parent1359da6ec09d60ac9aef28f2e0df4d7f712f08d3 (diff)
[ruby/irb] Suppress crash when bignum is set to SAVE_HISTORY
https://github.com/ruby/irb/commit/5044eb2730
Diffstat (limited to 'lib')
-rw-r--r--lib/irb/ext/save-history.rb7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/irb/ext/save-history.rb b/lib/irb/ext/save-history.rb
index edc4f234cc..2d9808259d 100644
--- a/lib/irb/ext/save-history.rb
+++ b/lib/irb/ext/save-history.rb
@@ -109,7 +109,12 @@ module IRB
open(history_file, "w:#{IRB.conf[:LC_MESSAGES].encoding}", 0600) do |f|
hist = history.map{ |l| l.split("\n").join("\\\n") }
- f.puts(hist[-num..-1] || hist)
+ begin
+ hist = hist.last(num) if hist.size > num
+ rescue RangeError # bignum too big to convert into `long'
+ # Do nothing because the bignum should be treated as inifinity
+ end
+ f.puts(hist)
end
end
end