emilk / loguru

A lightweight C++ logging library
The Unlicense
1.77k stars 256 forks source link

home_dir() fatal error on _win32 when using ~ in log file path #169

Closed mercurysky closed 3 years ago

mercurysky commented 3 years ago

Within the home_dir() function, the assertion CHECK_F has the incorrect logic for the return value of _dupenv_s on windows. It currently is asserting failure when errno_t is zero, which is not an error.

From documentation for _dupenv "Zero on success, an error code on failure"

I confirmed this in the debugger using MSVC2019 when a log file is provided of the form "~/mylogfile.log".

errno_t err = _dupenv_s(&user_profile, &len, "USERPROFILE");

Current

CHECK_F(err != 0, "Missing USERPROFILE");

Needed fix

CHECK_F(err == 0, "Missing USERPROFILE");