Skip to content

Commit

Permalink
Merge pull request #131 from meilinxiaoxue/master
Browse files Browse the repository at this point in the history
bugfix: handle space in file name
  • Loading branch information
RMichelsen authored Sep 27, 2024
2 parents 3e04fc8 + 258a600 commit 367190e
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -470,18 +470,19 @@ int WINAPI wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev_instance, _
// Otherwise assume the argument is a filename to open
else {
// Otherwise assume switch is for nvim initialization
const size_t arg_len = wcslen(cmd_line_args[i]) + 1 /* space */;
if (nvim_cmd_len + arg_len >= 32767) {
const size_t arg_len = wcslen(cmd_line_args[i]) /* space */;
if (nvim_cmd_len + arg_len + 4 >= 32767) {
MessageBoxA(NULL, "ERROR: File path too long", "Nvy", MB_OK | MB_ICONERROR);
return 1;
}
wchar_t *tmp = static_cast<wchar_t *>(realloc(nvim_cmd, sizeof(wchar_t) * (nvim_cmd_len + arg_len + 1)));
size_t tmp_len = sizeof(wchar_t) * (nvim_cmd_len + arg_len + 4);
wchar_t *tmp = static_cast<wchar_t *>(realloc(nvim_cmd, tmp_len));
if (tmp) {
nvim_cmd = tmp;
nvim_cmd[nvim_cmd_len] = L' ';
wmemcpy_s(nvim_cmd + nvim_cmd_len + 1, arg_len, cmd_line_args[i], arg_len);
nvim_cmd_len += arg_len;
nvim_cmd[nvim_cmd_len] = 0;
nvim_cmd_len = tmp_len;
wcscat_s(nvim_cmd, tmp_len, L" \"");
wcscat_s(nvim_cmd, tmp_len,cmd_line_args[i]);
wcscat_s(nvim_cmd, tmp_len, L"\"");
} else {
break; // not enough memory to continue
}
Expand Down

0 comments on commit 367190e

Please sign in to comment.