String concatenation segmentation error
tcak
tcak at gmail.com
Thu Apr 22 21:15:48 UTC 2021
string fileContent = "";
...
writeln(ri, ": debug 1");
foreach(i; 0..dim)
{
if( i > 0 ){ fileContent ~= "\t"; }
writeln(ri, ": debug 1.1: ", ri*dim + i, ": ", positions[ ri*dim
+ i ]);
fileContent ~= to!string(positions[ ri*dim + i ]);
writeln(ri, ": debug 1.2: ", ri*dim + i, ": ", positions[ ri*dim
+ i ]);
}
---------
On line "fileContent ~= ...", I get a segmentation fault.
"positions" array is defined as auto positions = new float[ 100
]; So, I am 100% sure, it is not out of range. "ri*dim + 1" is
not a big number at all.
...
4: debug 1.1: 9: 0.271075
4: debug 1.2: 9: 0.271075
4: debug 2
4: debug 2.1: 4
4: debug 3
4: debug 4
5: debug 1
5: debug 1.1: 10: 0.884978
5: debug 1.2: 10: 0.884978
5: debug 1.1: 11: 0.813104
Segmentation fault
...
I have compiled the code with "-g" flag and ran it with GNU
debugger. It gives following:
Thread 1 "dataspace" received signal SIGSEGV, Segmentation fault.
0x00005555556ca286 in
_D2gc4impl12conservativeQw3Gcx10smallAllocMFNbmKmkxC8TypeInfoZPv
()
So, there is a problem about small allocation. I remember I had
this problem before in another project.
I have enough free ram. htop shows 3.96 GiB of 8 GiB is used only
and swap is not in use.
DMD64 D Compiler v2.094.0
Is this error related to me? Is it a programmer error? Is it a
bug? Am I doing something wrong? This is a compiler related
operation (string concatenation), and I assume/expect that it
would work without a problem.
More information about the Digitalmars-d-learn
mailing list