Zcoin implementation bug enabled attacker to create 548, 000 Zcoins

Nick Treleaven via Digitalmars-d digitalmars-d at puremagic.com
Sat Mar 11 07:03:30 PST 2017


On Friday, 10 March 2017 at 19:02:06 UTC, H. S. Teoh wrote:
> A long-standing item on my todo list is to implement 
> compile-time writefln format strings using this technique.

Yes, the actual checking seems straightforward - here I 
implemented CT format as an overload:

import std.format : format;

auto format(string fmt, A...)(A args)
{
	static assert(__traits(compiles, {enum s = .format(fmt, 
A.init);}),
		"Arguments do not match format string: '" ~ fmt ~ "' with " ~ 
A.stringof);
	return .format(fmt, args);
}

unittest
{
	auto s = format!"%s is %s"(5, "five");
	static assert(!__traits(compiles, {s = format!"%d"("four");}));
}



More information about the Digitalmars-d mailing list