Skip to content

Commit ceee0e7

Browse files
committed
Fix bounds check in which()
1 parent 964a5a1 commit ceee0e7

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

unixlauncher.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@ static char *which(const char *const executable) {
3131
dirs[dirs_length] = ':';
3232

3333
size_t dir_head = 0;
34-
size_t i = 0;
35-
do {
34+
for (size_t i = 0; i <= dirs_length; i++) {
3635
if (dirs[i] == ':') {
3736
// Declare convenient path variables
3837
char *const dir = dirs + dir_head;
@@ -59,7 +58,7 @@ static char *which(const char *const executable) {
5958

6059
dir_head = i + 1;
6160
}
62-
} while (dirs[i++]);
61+
};
6362

6463
// Lookup has failed, free if necessary and return NULL
6564
if (exe_path != NULL) {

0 commit comments

Comments
 (0)