In the following code, with the error line marked with a "119", I get a SIGSEGV. Software distribution is arch linux on this machine.
var envs, wavs, fms, macros: seq[tuple[name: string, values: string]]
var name, artist: string = ""
var tickrate: int16 = 0
...
proc loadfile(filename: string): seq[tuple[blk: string, lin: string]] =
var wavblock, envblock, mublockplay, mublockloop, fmblock: bool = false
var metablock: bool = true
var counter: int = 0
block load:
for line in lines(filename):
counter.inc
echo counter
block read:
if line.startsWith('#'):
break read
elif line.startsWith("END"):
break load
elif line.isNilOrEmpty():
break read
elif line.isNilOrWhitespace():
break read
elif line.startsWith("/env"):
envblock = true
metablock = false
mublockplay = false
mublockloop = false
fmblock = false
wavblock = false
break read
elif line.startsWith("/wav"):
wavblock = true
metablock = false
mublockplay = false
mublockloop = false
fmblock = false
envblock = false
break read
elif line.startsWith("/fm"):
fmblock = true
metablock = false
mublockplay = false
mublockloop = false
envblock = false
wavblock = false
break read
elif line.startsWith("/mu1"):
mublockplay = true
fmblock = false
metablock = false
mublockloop = false
envblock = false
wavblock = false
break read
elif line.startsWith("/mu2"):
mublockloop = true
fmblock = false
metablock = false
mublockplay = false
envblock = false
wavblock = false
break read
elif metablock and line.startsWith("name="):
name = line
name.removePrefix("name=")
break read
elif metablock and line.startsWith("artist="):
artist = line
name.removePrefix("artist=")
break read
elif metablock and line.endsWith("hz"):
var templine = line
templine.removeSuffix("hz")
tickrate = templine.parseInt().int16
break read
elif mublockplay or mublockloop:
if mublockplay:
result.add(("mP", line))
break read
else:
result.add(("mL", line))
break read
elif envblock and not line.isNilOrEmpty():
119 result.add(("e", line))
break read
elif wavblock and not line.isNilOrEmpty():
result.add(("w", line))
break read
elif fmblock and not line.isNilOrEmpty():
result.add(("f", line))
break read
else:
break read
return
The code being read is in this linkĀ
File exists.
SIGSEGV happens after reading the first 6 lines (up to /env)
Possibly a bug?
"SIGSEGV (Attempt to read from nil?)"
You are reading from nil. You haven't initialised result. Use result = @[] at the top of your proc.
like @dom mentioned this
var envs, wavs, fms, macros: seq[tuple[name: string, values: string]]
all variables aren't initialized, you might to initialize them with newSeq[T] like
type
Info = object
name, value: string
var envs, wavs, fms, macros = newSeq[Info]()