Comment #0 by dlang-bugzilla — 2020-12-26T16:28:55Z
See the following program. According to semantics (return value), we call one overload, but codegen actually calls another:
//////////////////////////// test.d ///////////////////////////
@safe:
template toHex()
{
char[] toHex(in ubyte[] data, char[] buf) pure
{
assert(false, "Completely irrelevant overload");
}
char[n*2] toHex(size_t n)(in ubyte[n] data) pure
{
char[n*2] buf;
return buf;
}
string toHex(in ubyte[] data) pure
{
assert(false, "Should not be called"); // Is called
}
}
void main()
{
ubyte[40] hmacBytes;
// Semantics thinks that this will call the second overload
// (returning a static array),
// but codegen actually calls the third overload!
auto hmac = hmacBytes.toHex();
// Yes, according to the type of the return value,
// we called the second overload:
static assert(is(typeof(hmac) == char[80]));
}
///////////////////////////////////////////////////////////////
This seems to further confuse the compiler, and cause invalid slices to be passed to further consumers of the return value, leading to segfaults / memory corruption.
Comment #1 by dlang-bugzilla — 2023-02-27T19:03:41Z