Browse Source

Merge Reduce IsDive memory usage (PR#2455)

Richard Wackerbarth 10 years ago
parent
commit
c2760c3cac
1 changed files with 8 additions and 9 deletions
  1. 8
    9
      Marlin/cardreader.cpp

+ 8
- 9
Marlin/cardreader.cpp View File

56
     // If the entry is a directory and the action is LS_SerialPrint
56
     // If the entry is a directory and the action is LS_SerialPrint
57
     if (DIR_IS_SUBDIR(&p) && lsAction != LS_Count && lsAction != LS_GetFilename) {
57
     if (DIR_IS_SUBDIR(&p) && lsAction != LS_Count && lsAction != LS_GetFilename) {
58
 
58
 
59
-      // Allocate enough stack space for the full path to a folder, trailing slash, and nul
60
-      int len = strlen(prepend) + FILENAME_LENGTH + 1 + 1;
61
-      char path[len];
62
-
63
       // Get the short name for the item, which we know is a folder
59
       // Get the short name for the item, which we know is a folder
64
       char lfilename[FILENAME_LENGTH];
60
       char lfilename[FILENAME_LENGTH];
65
       createFilename(lfilename, p);
61
       createFilename(lfilename, p);
66
 
62
 
63
+      // Allocate enough stack space for the full path to a folder, trailing slash, and nul
64
+      boolean prepend_is_empty = (prepend[0] == '\0');
65
+      int len = (prepend_is_empty ? 1 : strlen(prepend)) + strlen(lfilename) + 1 + 1;
66
+      char path[len];
67
+
67
       // Append the FOLDERNAME12/ to the passed string.
68
       // Append the FOLDERNAME12/ to the passed string.
68
       // It contains the full path to the "parent" argument.
69
       // It contains the full path to the "parent" argument.
69
       // We now have the full path to the item in this folder.
70
       // We now have the full path to the item in this folder.
70
-      path[0] = '\0';
71
-      if (prepend[0] == '\0') strcat(path, "/"); // a root slash if prepend is empty
72
-      strcat(path, prepend);
73
-      strcat(path, lfilename);
74
-      strcat(path, "/");
71
+      strcpy(path, prepend_is_empty ? "/" : prepend); // root slash if prepend is empty
72
+      strcat(path, lfilename); // FILENAME_LENGTH-1 characters maximum
73
+      strcat(path, "/");       // 1 character
75
 
74
 
76
       // Serial.print(path);
75
       // Serial.print(path);
77
 
76
 

Loading…
Cancel
Save