瀏覽代碼

toolbox: appliciable fixes from 955729f.
End loop early if over index.
Only initialize space we use in the buffer.
Minor code reordering

Niels Martin Hansen 1 年之前
父節點
當前提交
a31577c45f
共有 1 個文件被更改,包括 5 次插入3 次删除
  1. 5 3
      src/BlueSCSI_Toolbox.cpp

+ 5 - 3
src/BlueSCSI_Toolbox.cpp

@@ -98,12 +98,13 @@ void onListFiles(const char * dir_name) {
     FsFile dir;
     FsFile file;
 
-    memset(scsiDev.data, 0, 4096);
+    memset(scsiDev.data, 0, ENTRY_SIZE * (MAX_FILE_LISTING_FILES + 1));
     char name[MAX_FILE_PATH] = {0};
-    dir.open(dir_name);
-    dir.rewindDirectory();
     uint8_t index = 0;
     byte file_entry[ENTRY_SIZE] = {0};
+
+    dir.open(dir_name);
+    dir.rewindDirectory();
     while (file.openNext(&dir, O_RDONLY))
     {
         memset(name, 0, MAX_FILE_PATH);
@@ -130,6 +131,7 @@ void onListFiles(const char * dir_name) {
         file_entry[39] = (size) & 0xff;
         memcpy(&(scsiDev.data[ENTRY_SIZE * index]), file_entry, ENTRY_SIZE);
         index = index + 1;
+        if (index >= MAX_FILE_LISTING_FILES) break;
     }
     dir.close();