Skip to content

wil::GetModuleFileNameW - string size is not adjusted #163

@m417z

Description

@m417z

Here's a snippet that demonstrates the issue:

#include <windows.h>
#include <string>
#include <iostream>
#include "wil/stl.h"
#include "wil/win32_helpers.h"

int main()
{
    std::wstring exePath = wil::GetModuleFileNameW<std::wstring>(nullptr);
    std::wcout << exePath << '\n';
    std::wcout << exePath.length() << '\n';
    std::wcout << wcslen(exePath.c_str()) << '\n';
}

An example output:

C:\Users\User\source\repos\ConsoleApplication1\x64\Release\ConsoleApplication1.exe
127
82

As you can see, the string size is not adjusted after calling GetModuleFileNameW internally.

By the way, if you remove #include "wil/stl.h" and try to compile in Release, the compiler crashes. I reported about it in the compiler feedback.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions