Hi @cardinot, 
Sorry I was wrong in my fist comment. 

I have thought to this, which works fine:  
wchar_t tmp[size]; 
memset(tmp, 0, sizeof(tmp));

But since wchar_t* tmp is just a pointer without array size info it does not work 

Old version: 
memset(tmp, 0, sizeof(tmp[0]) * sizeof(tmp)); 
sizeof(tmp[0]) = 4 
sizeof(tmp) = 8 @ 64 bit Os 

Current version 
memset(tmp, 0, sizeof(*tmp));
sizeof(*tmp) = 4 

Working version for zero out the whole buffer: 
memset(tmp, 0, sizeof(*tmp) * (max_length+1));

But actually this is not required here. 
Zero the addition byte only will be sufficient:
tmp[max_length] = 0;