Skip to content
This repository has been archived by the owner on Oct 12, 2022. It is now read-only.

Commit

Permalink
Supplemental fix for issue 13902, don't return a slice to local stati…
Browse files Browse the repository at this point in the history
…c array.
  • Loading branch information
9rnsr committed Jan 11, 2015
1 parent a0c35e1 commit b526fbd
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/core/internal/convert.d
Expand Up @@ -479,7 +479,7 @@ const(ubyte)[] toUbyte(T)(T[] arr) if (T.sizeof == 1)
}

@trusted pure nothrow
const(ubyte)[] toUbyte(T)(T[] arr) if ((is(typeof(toUbyte(arr[0])) == const(ubyte)[]))&&(T.sizeof > 1))
const(ubyte)[] toUbyte(T)(T[] arr) if ((is(typeof(toUbyte(arr[0])) == const(ubyte)[])) && (T.sizeof > 1))
{
if (__ctfe)
{
Expand Down Expand Up @@ -514,17 +514,15 @@ const(ubyte)[] toUbyte(T)(ref T val) if (__traits(isIntegral, T) && !is(T == enu
{
ubyte[T.sizeof] tmp;
Unqual!T val_ = val;
for (size_t i=0; i<T.sizeof; ++i)
for (size_t i = 0; i < T.sizeof; ++i)
{
size_t idx;
version(LittleEndian) idx = i;
else idx = T.sizeof-i-1;
tmp[idx] = cast(ubyte)(val_&0xff);
val_ >>= 8;
}

return tmp[];

return tmp[].dup;
}
else
{
Expand Down Expand Up @@ -628,7 +626,7 @@ const(ubyte)[] toUbyte(T)(ref T val) if (is(T == struct) || is(T == union))
assert(0, "Unable to compute byte representation of "~typeof(CUR_TYPE).stringof~" field at compile time");
}
}
return bytes[];
return bytes[].dup;
}
else
{
Expand Down

0 comments on commit b526fbd

Please sign in to comment.