Vladimir Panteleev git@vladimir.panteleev.md writes:
@@ -1234,7 +1234,9 @@ DWORD WINAPI DECLSPEC_HOTPATCH GetEnvironmentVariableA( LPCSTR name, LPSTR value { UNICODE_STRING us_name; PWSTR valueW;
- DWORD ret;
DWORD ret, last_err;
last_err = GetLastError();
/* limit the size to sane values */ size = min( size, 32767 );
@@ -1249,7 +1251,11 @@ DWORD WINAPI DECLSPEC_HOTPATCH GetEnvironmentVariableA( LPCSTR name, LPSTR value * - an error (GetLastError() != 0) * - returning an empty string (in this case, we need to update the buffer) */
- if (ret == 0 && size && GetLastError() == 0) value[0] = 0;
- if (GetLastError() == 0)
- {
SetLastError(last_err);
if (ret == 0 && size) value[0] = 0;
- }
It would be cleaner to avoid changing last error at all, instead of saving and restoring it.