Repository: xbmc/xbmc
File: xbmc/platform/win32/filesystem/Win32SMBDirectory.cpp (C++)

Code before:
      if (bufSize > buf.size())
      { // buffer is too small
        buf.resize(bufSize); // discard buffer content and extend the buffer
        bufSize = buf.size();
        result =
            WNetEnumResourceW(netEnum, &resCount, buf.data(), reinterpret_cast<LPDWORD>(&bufSize));
        if (result != NO_ERROR || bufSize > buf.size())
          errorFlag = true; // hardly ever happens
      }

      for (unsigned int i = 0; i < resCount && !errorFlag; i++)
      {
        _NETRESOURCEW& curResource = ((_NETRESOURCEW*)buf.data())[i];

        /* check and collect servers */
        if (!getShares && curResource.dwDisplayType == RESOURCEDISPLAYTYPE_SERVER)
        {
          if (curResource.lpRemoteName != NULL)
          {
            std::wstring remoteName(curResource.lpRemoteName);
            if (remoteName.length() > 2 && remoteName.compare(0, 2, L"\\\\", 2) == 0)
            {
              std::string remoteNameUtf8;
              if (g_charsetConverter.wToUTF8(remoteName.substr(2), remoteNameUtf8, true) && !remoteNameUtf8.empty())
              {
                std::shared_ptr<CFileItem> pItem(new CFileItem(remoteNameUtf8));
                pItem->SetPath(urlPrefixForItems + remoteNameUtf8 + '/');
                pItem->SetFolder(true);
                items.Add(pItem);
              }
              else
                CLog::LogF(LOGERROR,
                           "Can't convert server wide string name \"{}\" to UTF-8 encoding",
                           FromW(remoteName.substr(2)));
            }
            else
              CLog::LogF(LOGERROR, "Skipping server name \"{}\" without '\\' prefix",
                         FromW(remoteName));
          }
          else
            CLog::LogF(LOGERROR, "Skipping server with empty remote name");
        }

        /* check and collect shares */
        if (getShares && (curResource.dwDisplayType == RESOURCEDISPLAYTYPE_SHARE ||
                          curResource.dwDisplayType == RESOURCEDISPLAYTYPE_SHAREADMIN) &&
                          curResource.dwType != RESOURCETYPE_PRINT)
        {
          if (curResource.lpRemoteName != NULL)
          {
            std::wstring serverShareName(curResource.lpRemoteName);

Review comment (suggestion):
```suggestion
                std::shared_ptr<CFileItem> item = std::make_shared<CFileItem>(remoteNameUtf8);
                item->SetPath(urlPrefixForItems + remoteNameUtf8 + '/');
                item->SetFolder(true);
                items.Add(pItem);
```

Code after:
            if (remoteName.length() > 2 && remoteName.compare(0, 2, L"\\\\", 2) == 0)
            {
              std::string remoteNameUtf8;
              if (g_charsetConverter.wToUTF8(remoteName.substr(2), remoteNameUtf8, true) && !remoteNameUtf8.empty())
              {
                CFileItemPtr pItem(new CFileItem(remoteNameUtf8));
                pItem->SetPath(urlPrefixForItems + remoteNameUtf8 + '/');
                pItem->SetFolder(true);
                items.Add(pItem);
              }
              else
                CLog::LogF(LOGERROR,
                           "Can't convert server wide string name \"{}\" to UTF-8 encoding",
                           FromW(remoteName.substr(2)));
            }
            else
              CLog::LogF(LOGERROR, "Skipping server name \"{}\" without '\\' prefix",
                         FromW(remoteName));
          }
          else
            CLog::LogF(LOGERROR, "Skipping server with empty remote name");
        }

        /* check and collect shares */
        if (getShares && (curResource.dwDisplayType == RESOURCEDISPLAYTYPE_SHARE ||
                          curResource.dwDisplayType == RESOURCEDISPLAYTYPE_SHAREADMIN) &&
                          curResource.dwType != RESOURCETYPE_PRINT)
        {
          if (curResource.lpRemoteName != NULL)
          {
            std::wstring serverShareName(curResource.lpRemoteName);
            if (serverShareName.length() > 2 && serverShareName.compare(0, 2, L"\\\\", 2) == 0)
            {
              const size_t slashPos = serverShareName.rfind('\\');
              if (slashPos < serverShareName.length() - 1) // slash must be not on last position
              {
                std::string shareNameUtf8;
                if (g_charsetConverter.wToUTF8(serverShareName.substr(slashPos + 1), shareNameUtf8, true) && !shareNameUtf8.empty())
                {
                  CFileItemPtr pItem(new CFileItem(shareNameUtf8));
                  pItem->SetPath(urlPrefixForItems + shareNameUtf8 + '/');
                  pItem->SetFolder(true);
                  if (curResource.dwDisplayType == RESOURCEDISPLAYTYPE_SHAREADMIN)
                    pItem->SetProperty("file:hidden", true);

                  items.Add(pItem);
                }
                else
                {
                  CLog::LogF(
                      LOGERROR,