check string lengths to avoid index out of bound
This commit is contained in:
parent
39988eb1cf
commit
aefa6547c3
1 changed files with 4 additions and 2 deletions
|
|
@ -139,6 +139,7 @@ proc findExe*(exe: string, followSymlinks: bool = true;
|
||||||
## is added the `ExeExts <#ExeExts>`_ file extensions if it has none.
|
## is added the `ExeExts <#ExeExts>`_ file extensions if it has none.
|
||||||
## If the system supports symlinks it also resolves them until it
|
## If the system supports symlinks it also resolves them until it
|
||||||
## meets the actual file. This behavior can be disabled if desired.
|
## meets the actual file. This behavior can be disabled if desired.
|
||||||
|
if exe.len == 0: return
|
||||||
template checkCurrentDir() =
|
template checkCurrentDir() =
|
||||||
for ext in extensions:
|
for ext in extensions:
|
||||||
result = addFileExt(exe, ext)
|
result = addFileExt(exe, ext)
|
||||||
|
|
@ -149,8 +150,9 @@ proc findExe*(exe: string, followSymlinks: bool = true;
|
||||||
checkCurrentDir()
|
checkCurrentDir()
|
||||||
let path = string(getEnv("PATH"))
|
let path = string(getEnv("PATH"))
|
||||||
for candidate in split(path, PathSep):
|
for candidate in split(path, PathSep):
|
||||||
|
if candidate.len == 0: continue
|
||||||
when defined(windows):
|
when defined(windows):
|
||||||
var x = (if candidate[0] == '"' and candidate[^1] == '"':
|
var x = (if candidate.len > 2 and candidate[0] == '"' and candidate[^1] == '"':
|
||||||
substr(candidate, 1, candidate.len-2) else: candidate) /
|
substr(candidate, 1, candidate.len-2) else: candidate) /
|
||||||
exe
|
exe
|
||||||
else:
|
else:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue