Skip to content
This repository was archived by the owner on Nov 21, 2018. It is now read-only.

Commit a91b91b

Browse files
committed
Fix parsing PATH on windows
Thanks to @vadimcn for the patch!
1 parent 6f62d62 commit a91b91b

File tree

1 file changed

+24
-27
lines changed

1 file changed

+24
-27
lines changed

src/win/process.c

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -373,15 +373,6 @@ static WCHAR* search_path(const WCHAR *file,
373373
name_has_ext);
374374

375375
while (result == NULL) {
376-
if (*dir_end == L'\0') {
377-
break;
378-
}
379-
380-
/* Skip the separator that dir_end now points to */
381-
if (dir_end != path) {
382-
dir_end++;
383-
}
384-
385376
/* Next slice starts just after where the previous one ended */
386377
dir_start = dir_end;
387378

@@ -392,27 +383,33 @@ static WCHAR* search_path(const WCHAR *file,
392383
}
393384

394385
/* If the slice is zero-length, don't bother */
395-
if (dir_end - dir_start == 0) {
396-
continue;
386+
if (dir_end - dir_start > 0) {
387+
dir_path = dir_start;
388+
dir_len = dir_end - dir_start;
389+
390+
/* Adjust if the path is quoted. */
391+
if (dir_path[0] == '"' || dir_path[0] == '\'') {
392+
++dir_path;
393+
--dir_len;
394+
}
395+
396+
if (dir_path[dir_len - 1] == '"' || dir_path[dir_len - 1] == '\'') {
397+
--dir_len;
398+
}
399+
400+
result = path_search_walk_ext(dir_path, dir_len,
401+
file, file_len,
402+
cwd, cwd_len,
403+
name_has_ext);
397404
}
398405

399-
dir_path = dir_start;
400-
dir_len = dir_end - dir_start;
401-
402-
/* Adjust if the path is quoted. */
403-
if (dir_path[0] == '"' || dir_path[0] == '\'') {
404-
++dir_path;
405-
--dir_len;
406-
}
407-
408-
if (dir_path[dir_len - 1] == '"' || dir_path[dir_len - 1] == '\'') {
409-
--dir_len;
406+
/* Stop if reached end of the line */
407+
if (*dir_end == L'\0') {
408+
break;
410409
}
411-
412-
result = path_search_walk_ext(dir_path, dir_len,
413-
file, file_len,
414-
cwd, cwd_len,
415-
name_has_ext);
410+
411+
/* Skip the separator that dir_end now points to */
412+
dir_end++;
416413
}
417414
}
418415

0 commit comments

Comments
 (0)