Nikolay Sivov (@nsivov) commented about dlls/kernelbase/process.c:
us_dst.Buffer = dst;
+ /* Tests show windows keeps the last character instead of a null terminator */ + if (dst && len) last_char = dst[len - 1]; res = 0; status = RtlExpandEnvironmentStrings_U( NULL, &us_src, &us_dst, &res ); res /= sizeof(WCHAR); - if (!set_ntstatus( status )) + if (status != STATUS_BUFFER_TOO_SMALL) { - if (status != STATUS_BUFFER_TOO_SMALL) return 0; - if (len && dst) dst[len - 1] = 0; + if (!set_ntstatus( status )) return 0; } + else if (dst && len) dst[len - 1] = last_char; +
There must be a better way. Instead of putting it back, it shouldn't have been written to in a first place. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/4045#note_53766