<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On 21 March 2013 20:29, Jacob Carlborg <span dir="ltr"><<a href="mailto:doob@me.com" target="_blank">doob@me.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The code below works fine without optimizations. But with optimizations (the -O flag) turned on it segfaults. The behavior with optimizations turned on is a bit different depending on which version of DMD I try and if I compile for 32 or 64bit.<br>

<br>
DMD 2.062 64bit: Segfault<br>
DMD 2.062 32bit: Prints a huge array then segfault<br>
DMD 2.061 64bit: Segfault<br>
DMD 2.061 32bit: Prints a fairly small array (10 elements) with random numbers<br>
DMD head (7dcc72a997) 32bit: Bus error: 10<br>
<br>
I'm using Mac OS X 10.8.2.<br>
<br>
import std.stdio;<br>
<br>
int[]* getDeserializedSlice ()<br>
{<br>
    void[] a = [1, 2, 3, 4, 5].dup;<br>
    auto b = &a;<br>
<br>
    if (auto c = b)<br>
        auto d = &(cast(int[]) *c)[1 .. 1 + 2];<br>
<br>
    return null;<br>
}<br>
<br>
void main ()<br>
{<br>
    writeln(*getDeserializedSlice(<u></u>));<br>
}<br>
<br>
Is the above code supposed to work? The test case might look a bit strange, the full source code is here:<br>
<br>
<a href="https://github.com/jacob-carlborg/orange/blob/master/orange/serialization/Serializer.d#L1672" target="_blank">https://github.com/jacob-<u></u>carlborg/orange/blob/master/<u></u>orange/serialization/<u></u>Serializer.d#L1672</a><span class="HOEnZb"><font color="#888888"><br>

<br>
-- <br>
/Jacob Carlborg<br>
</font></span></blockquote></div><br><br></div><div class="gmail_extra">As I see it, that code should *always* cause a segmentation fault.<br><br></div><div class="gmail_extra">You are returning 'null', and then dereferencing it...<br>
</div><div class="gmail_extra"><br clear="all"><br></div><div class="gmail_extra">Regards<br></div><div class="gmail_extra">-- <br>Iain Buclaw<br><br>*(p < e ? p++ : p) = (c & 0x0f) + '0';
</div></div>