Skip to content

Commit 65f3d78

Browse files
committed
Switch for loop to while loop
1 parent e82f062 commit 65f3d78

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/library_syscall.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -701,9 +701,9 @@ var SyscallsLibrary = {
701701
var pos = 0;
702702
var off = FS.llseek(stream, 0, {{{ cDefs.SEEK_CUR }}});
703703
704-
var idx = Math.floor(off / struct_size);
705-
706-
while (idx < stream.getdents.length && pos + struct_size <= count) {
704+
var startIdx = Math.floor(off / struct_size);
705+
var endIdx = Math.min(stream.getdents.length, startIdx + Math.floor(count/struct_size))
706+
for (var idx = startIdx; idx < endIdx; idx++) {
707707
var id;
708708
var type;
709709
var name = stream.getdents[idx];
@@ -724,7 +724,6 @@ var SyscallsLibrary = {
724724
// If the entry is not a directory, file, or symlink, nodefs
725725
// lookupNode will raise EINVAL. Skip these and continue.
726726
if (e?.errno === {{{ cDefs.EINVAL }}}) {
727-
idx += 1;
728727
continue;
729728
}
730729
throw e;
@@ -744,7 +743,6 @@ var SyscallsLibrary = {
744743
{{{ makeSetValue('dirp + pos', C_STRUCTS.dirent.d_type, 'type', 'i8') }}};
745744
stringToUTF8(name, dirp + pos + {{{ C_STRUCTS.dirent.d_name }}}, 256);
746745
pos += struct_size;
747-
idx += 1;
748746
}
749747
FS.llseek(stream, idx * struct_size, {{{ cDefs.SEEK_SET }}});
750748
return pos;

0 commit comments

Comments
 (0)