mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-01 02:42:05 +00:00
shallow() casts its string argument to a seq and then tries to access
its fields. Guess what happens when that string is nil, which seems to
be the representation of an empty string (both the default value and an
explicitly assigned "").
Segfault encountered when running "ntags -R ." on a large project. The relevant line:
a1c62c38e5/ntags.nim (lines-125)
33 lines
460 B
Nim
33 lines
460 B
Nim
discard """
|
|
output: '''@["", "", "", "", "", "", "", "meh"]'''
|
|
exitcode: "0"
|
|
"""
|
|
|
|
when true:
|
|
var ab: string
|
|
ab &= "more"
|
|
|
|
doAssert ab == "more"
|
|
|
|
var x: seq[string]
|
|
|
|
setLen(x, 7)
|
|
|
|
x.add "meh"
|
|
|
|
var s: string
|
|
var z = "abc"
|
|
var zz: string
|
|
s &= "foo" & z & zz
|
|
|
|
doAssert s == "fooabc"
|
|
|
|
echo x
|
|
|
|
# casting an empty string as sequence with shallow() should not segfault
|
|
var s2: string
|
|
shallow(s2)
|
|
s2 &= "foo"
|
|
doAssert s2 == "foo"
|
|
|