/* WARNING: There is no check for overflow later when this buffer is
* being used! But it's as long as the maximum path length understood
* by Windows NT (which is NOT the same as MAX_PATH). */
- path = MALLOC(WINDOWS_NT_MAX_PATH * sizeof(wchar_t));
- if (!path)
+ path = MALLOC((WINDOWS_NT_MAX_PATH + 1) * sizeof(wchar_t));
+ if (path == NULL)
return WIMLIB_ERR_NOMEM;
/* Work around defective behavior in Windows where paths longer than 260
* turned into absolute paths and prefixed with "\\?\". */
if (wcsncmp(root_disk_path, L"\\\\?\\", 4)) {
- dret = GetFullPathName(root_disk_path, WINDOWS_NT_MAX_PATH - 4,
+ dret = GetFullPathName(root_disk_path, WINDOWS_NT_MAX_PATH - 3,
&path[4], NULL);
- if (dret == 0 || dret >= WINDOWS_NT_MAX_PATH - 4) {
+ if (dret == 0 || dret >= WINDOWS_NT_MAX_PATH - 3) {
WARNING("Can't get full path name for \"%ls\"", root_disk_path);
wmemcpy(path, root_disk_path, path_nchars + 1);
} else {