[Orc] fixes "streams.readDataStr segafaults" when accepting a string literal (#20019) [backport]
fixes streams.readDataStr accept a string literal
This commit is contained in:
parent
800cb006e7
commit
286fcef68e
2 changed files with 15 additions and 0 deletions
|
|
@ -1197,6 +1197,11 @@ else: # after 1.3 or JS not defined
|
||||||
|
|
||||||
proc ssReadDataStr(s: Stream, buffer: var string, slice: Slice[int]): int =
|
proc ssReadDataStr(s: Stream, buffer: var string, slice: Slice[int]): int =
|
||||||
var s = StringStream(s)
|
var s = StringStream(s)
|
||||||
|
when nimvm:
|
||||||
|
discard
|
||||||
|
else:
|
||||||
|
when declared(prepareMutation):
|
||||||
|
prepareMutation(buffer) # buffer might potentially be a CoW literal with ARC
|
||||||
result = min(slice.b + 1 - slice.a, s.data.len - s.pos)
|
result = min(slice.b + 1 - slice.a, s.data.len - s.pos)
|
||||||
if result > 0:
|
if result > 0:
|
||||||
jsOrVmBlock:
|
jsOrVmBlock:
|
||||||
|
|
|
||||||
|
|
@ -85,3 +85,13 @@ block:
|
||||||
static: # Ensure streams it doesnt break with nimscript on arc/orc #19716
|
static: # Ensure streams it doesnt break with nimscript on arc/orc #19716
|
||||||
let s = newStringStream("a")
|
let s = newStringStream("a")
|
||||||
doAssert s.data == "a"
|
doAssert s.data == "a"
|
||||||
|
|
||||||
|
template main =
|
||||||
|
var strm = newStringStream("abcde")
|
||||||
|
var buffer = "12345"
|
||||||
|
doAssert strm.readDataStr(buffer, 0..3) == 4
|
||||||
|
doAssert buffer == "abcd5"
|
||||||
|
strm.close()
|
||||||
|
|
||||||
|
static: main()
|
||||||
|
main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue