You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
refactor: Extract GetExecutablePath helper in analytics_windows.cc
I've refactored `VerifyAndLoadAnalyticsLibrary` in `analytics_windows.cc`
to improve readability and modularity by extracting the logic for
obtaining the executable's full path into a new static helper
function `GetExecutablePath()`.
- The new `GetExecutablePath()` function encapsulates the prioritized
use of `_get_wpgmptr()`, fallback to `_get_pgmptr()`, and the
necessary `MultiByteToWideChar` conversion, along with all
associated error handling and logging. It returns `std::wstring`.
- `VerifyAndLoadAnalyticsLibrary` now calls `GetExecutablePath()` and
checks its return value before proceeding with path manipulation.
- This change makes `VerifyAndLoadAnalyticsLibrary` shorter and easier
to understand.
All previous security enhancements and fixes are maintained.
if (MultiByteToWideChar(CP_ACP, MB_ERR_INVALID_CHARS, pgmptr_val, -1, wide_path_buffer.data(), wide_char_count) == 0) {
171
+
DWORD conversion_error = GetLastError();
172
+
LogError("VerifyAndLoadAnalyticsLibrary: MultiByteToWideChar failed to convert _get_pgmptr path. Error: %u", conversion_error);
173
+
returnnullptr;
174
+
}
175
+
executable_path_str = wide_path_buffer.data();
176
+
} else {
177
+
// Both _get_wpgmptr and _get_pgmptr failed or returned empty/null
178
+
LogError("VerifyAndLoadAnalyticsLibrary: Failed to retrieve executable path using both _get_wpgmptr (err: %d) and _get_pgmptr (err: %d).", err_w, err_c);
179
+
returnnullptr;
180
+
}
181
+
}
182
+
183
+
if (executable_path_str.empty()) {
184
+
LogError("VerifyAndLoadAnalyticsLibrary: Executable path resolved to an empty string.");
0 commit comments