Closed
Description
Code:
let a = "hello".cstring
Default nim generates:
N_LIB_PRIVATE NIM_CONST NCSTRING a__xxx= "hello";
but with --gc:arc
this results in:
static struct {
NI cap; NIM_CHAR data[5+1];
} TM__xxx = { 5 | NIM_STRLIT_FLAG, "hello" };
N_LIB_PRIVATE NIM_CONST NCSTRING a__yyy = {5, (NimStrPayload*)&TM__xxx};
(mangling replaced by xxx
and yyy
for readability)
Using the cstring results in a SIGSEGV:
let a = "hello".cstring
echo a
nim c --gc:arc -r t2.nim
==168972== Memcheck, a memory error detector
==168972== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==168972== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==168972== Command: ./t2
==168972==
==168972== Invalid read of size 1
==168972== at 0x4839C62: strlen (vg_replace_strmem.c:461)
==168972== by 0x10A462: nimCStrLen (stdlib_system.nim.c:1089)
==168972== by 0x10D1A8: cstrToNimstr (stdlib_system.nim.c:2010)
==168972== by 0x112568: NimMainModule (@mt2.nim.c:153)
==168972== by 0x11243B: NimMainInner (@mt2.nim.c:119)
==168972== by 0x112468: NimMain (@mt2.nim.c:127)
==168972== by 0x1124A2: main (@mt2.nim.c:134)
==168972== Address 0x5 is not stack'd, malloc'd or (recently) free'd
==168972==
Traceback (most recent call last)
Metadata
Metadata
Assignees
Labels
No labels