wcsncpy(d,s,n) did not decrease n while copying the '\0' so when s[0]=0 and n=1 it wrote 2 zeros to d