michallenc commented on code in PR #18697:
URL: https://github.com/apache/nuttx/pull/18697#discussion_r3065285158


##########
fs/fat/fs_fat32dirent.c:
##########
@@ -1121,17 +1138,35 @@ static int fat_path2dirname(FAR const char **path,
   /* Assume no long file name */
 
   dirinfo->fd_lfname[0] = '\0';
+  dirinfo->fd_name[0] = '\0';
 
-  /* Then parse the (assumed) 8+3 short file name */
+  /* Parse long file name */
 
-  ret = fat_parsesfname(path, dirinfo, terminator);
+  ret = fat_parselfname(path, dirinfo, terminator);
   if (ret < 0)
     {
-      /* No, the name is not a valid short 8+3 file name. Try parsing
-       * the long file name.
+      return ret;
+    }
+  else
+    {
+      /* Does the long file name fit into short file name? This means
+       * this is actually a short file name.
+       *
+       * There are following possibilities:
+       *   - file was created on Linux and is written as long file name
+       *   - file was created on Windows and is written as short file name
+       *   - we are creating file on NuttX -> write it as short file name
        */
 
-      ret = fat_parselfname(path, dirinfo, terminator);
+      if (strlen((FAR const char *)dirinfo->fd_lfname) <= DIR_MAXFNAME)
+        {
+          /* Get short file name for given path */
+
+          char *name = kmm_zalloc(DIR_MAXFNAME);

Review Comment:
   You mean inside `fat_parsesfname`? We can't because it takes the full file 
path and goes over it -> so it may be `sub1/sub2/name`, not necessarily limited 
to 11 characters.
   
   Defining it directly on line 1165 leads to hard fault because of its usage 
`fat_parsesfname`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to