Repository navigation
Take long indexes in String#[]=, slice! and insert - #10104
Open
sampokuokkanen wants to merge 1 commit into
Open
sampokuokkanen wants to merge 1 commit into
sampokuokkanen wants to merge 1 commit into
Conversation
[]= narrowed its index and length to int, so an Integer outside int
range went wrong:
s = +"abc"; s[2**40] = "x" # s == "xbc", CRuby IndexError
s = +"abc"; s[0, 2**40] = "x" # RangeError, CRuby s == "x"
s = +"abc"; s[0..2**40] = "x" # RangeError, CRuby s == "x"
"abc".slice!(0, 2**40) # RangeError, CRuby "abc"
"abc".insert(2**40, "x") # RangeError, CRuby IndexError
Like rb_str_update, StringSupport.strUpdate now takes longs and checks
them against the character length, so both fit in an int afterwards.
The int overload delegates to it. Ranges use the long RubyRange#begLen,
whose RangeError message now shows the range as given, like begLenInt.
getbyte, setbyte, byteindex and bytesplice still narrow to int.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #10075, same fix for
String#[]=,slice!andinsert:StringSupport.strUpdatenow takes longs and checks them likerb_str_update. Range forms use the longRubyRange#begLen, whose RangeError message now matchesbegLenInt.Not fixed:
getbyte,setbyte,byteindexandbytesplicestill use int.(+"a") << (2**32 + 65)appends"A"instead of raising RangeError.