You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/07/18 13:39:48 UTC

[GitHub] [incubator-nuttx] acassis commented on pull request #4171: fs/tmpfs: Handle the tail '/' correctly

acassis commented on pull request #4171:
URL: https://github.com/apache/incubator-nuttx/pull/4171#issuecomment-882058101


   @xiaoxiang781216 what you think of this modification:
   ```
   +++ b/fs/tmpfs/fs_tmpfs.c
   @@ -463,6 +463,8 @@ static int tmpfs_find_dirent(FAR struct tmpfs_directory_s *tdo,
        {
          /* Ignore the tail '/' */
    
   +      name[len - 1] = '\0';
   +
          if (--len == 0)
            {
              return -EINVAL;
   @@ -473,8 +475,8 @@ static int tmpfs_find_dirent(FAR struct tmpfs_directory_s *tdo,
    
      for (i = 0;
           i < tdo->tdo_nentries &&
   -       (strncmp(tdo->tdo_entry[i].tde_name, name, len) != 0 ||
   -       tdo->tdo_entry[i].tde_name[len] != 0);
   +       (tdo->tdo_entry[i].tde_name[len] != 0 ||
   +        strncmp(tdo->tdo_entry[i].tde_name, name, len) != 0);
           i++);
    
      /* Return what we found, if anything */
   ```
   It will save processing time, because most of time the strncmp will not be executed.


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org