Repository: xbmc/xbmc
File: xbmc/filesystem/NFSDirectory.cpp (C++)

Code before:
        URIUtils::AddSlashAtEnd(myStrPath); //be sure the dir ends with a slash
        return GetDirectoryFromExportList(myStrPath, items);
      }
    }
    return false;
  }

  struct nfsdir* nfsdir = NULL;
  if (nfs_opendir(gNfsConnection.GetNfsContext(), strDirName.c_str(), &nfsdir) != 0)
  {
    CLog::Log(LOGERROR, "Failed to open({}) {}", strDirName,
              nfs_get_error(gNfsConnection.GetNfsContext()));
    return false;
  }
  lock.unlock();

  const std::vector<std::string> exclusions = {".", "..", "lost+found"};
  const auto notExcluded = exclusions.end();

  std::string myStrPath(url.Get());
  URIUtils::AddSlashAtEnd(myStrPath);
  URIUtils::AddSlashAtEnd(strDirName);

  std::string resolvedPath;
  std::vector<CFileItemPtr> fileItems;
  struct nfsdirent* dirent = NULL;
  while ((dirent = nfs_readdir(gNfsConnection.GetNfsContext(), nfsdir)) != NULL)
  {
    const std::string& strName = dirent->name;

    //resolve symlinks
    //resolve symlink changes dirent and strName
    const bool isSymLink = dirent->type == NF3LNK;
    if (isSymLink && !ResolveSymlink(strDirName, dirent, resolvedPath))
      continue;

    if (std::ranges::find(exclusions, strName) == notExcluded)
    {
      const bool bIsDir = dirent->type == NF3DIR;

      std::string path = isSymLink ? resolvedPath : (myStrPath + strName);
      if (bIsDir)
        URIUtils::AddSlashAtEnd(path);

      CFileItemPtr& pItem = fileItems.emplace_back(std::make_shared<CFileItem>(strName));
      pItem->SetDateTime(GetDirEntryTime(dirent));
      pItem->SetSize(dirent->size);
      pItem->SetFolder(bIsDir);
      pItem->SetPath(path);
      if (strName[0] == '.')
        pItem->SetProperty("file:hidden", true);

Review comment (bug):
```suggestion
  struct nfsdirent* dirent = nullptr;
```

Code after:
    return false;
  }

  struct nfsdir* nfsdir = nullptr;
  if (nfs_opendir(gNfsConnection.GetNfsContext(), strDirName.c_str(), &nfsdir) != 0)
  {
    CLog::Log(LOGERROR, "Failed to open({}) {}", strDirName,
              nfs_get_error(gNfsConnection.GetNfsContext()));
    return false;
  }
  lock.unlock();

  std::string myStrPath(url.Get());
  URIUtils::AddSlashAtEnd(myStrPath);
  URIUtils::AddSlashAtEnd(strDirName);

  std::string resolvedPath;
  std::vector<CFileItemPtr> fileItems;
  struct nfsdirent* dirent = nullptr;
  while ((dirent = nfs_readdir(gNfsConnection.GetNfsContext(), nfsdir)) != nullptr)
  {
    const std::string& name = dirent->name;

    //resolve symlinks
    //resolve symlink changes dirent and name
    const bool isSymLink = dirent->type == NF3LNK;
    if (isSymLink && !ResolveSymlink(strDirName, dirent, resolvedPath))
      continue;

    if (name == "." || name == ".." || name == "lost+found")
      continue;

    const bool isDir = dirent->type == NF3DIR;

    std::string path = isSymLink ? resolvedPath : (myStrPath + name);
    if (isDir)
      URIUtils::AddSlashAtEnd(path);

    auto& item = fileItems.emplace_back(std::make_shared<CFileItem>(name));
    item->SetPath(path);
    item->SetDateTime(GetDirEntryTime(dirent));
    item->SetFolder(isDir);
    item->SetSize(dirent->size);

    if (name[0] == '.')
      item->SetProperty("file:hidden", true);
  }
  items.AddItems(std::move(fileItems));

  lock.lock();
  nfs_closedir(gNfsConnection.GetNfsContext(), nfsdir); //close the dir