7670 - Fixed Windows chromium-args 260 character limit
https://github.com/nwjs/nw.js/issues/7670
Untested change for handling ExpandEnvironmentStrings on Windows. The original code limited chromium-args to 260 characters.
Note, I haven't tried to compile this, and my C++ is rusty. Figured I'd get this started to speed along a fix. It might be fine.
ExpandEnvironmentStrings returns the size of the expected character array, so if it's say 10K characters that are required for szEnvPath then it needs to be reallocated on the stack to the size of the returned value. I used a loop here to rerun ExpandEnvironmentStrings with the resized character array. This seemed like the most elegant way to write it since the return value needs to be checked again.
Is this PR still valid? this bug is still present in 0.91.0
@rogerwang Feel free to close this and rewrite it without the do while loop. Glancing at the code you're right that I overcomplicated it.
You can actually just call the function with nullptr and 0 to get back the required size, then just allocated to that size. Something like this:
DWORD requiredSize = ExpandEnvironmentStringsW(input.c_str(), nullptr, 0);
if (requiredSize > 0) {
std::wstring output(requiredSize, L'\0');
DWORD expandedSize = ExpandEnvironmentStringsW(input.c_str(), &output[0], requiredSize);
if (expandedSize > 0 && expandedSize <= requiredSize) {
// Trim null terminator
output.resize(expandedSize - 1);
// ...
} else {
// Handle error
}
} else {
// Handle error
}
This bug is still present in 0.92.0 - it would be fantastic if it could be resolved soonest
close as fixed.