Skip to content

Commit c760812

Browse files
committed
[FIX] : fix warnings with free version of PVS-Studio
1 parent bd525bf commit c760812

2 files changed

Lines changed: 64 additions & 62 deletions

File tree

ImGuiFileDialog.cpp

Lines changed: 61 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,8 @@ namespace IGFD
320320
//// FILE EXTENTIONS INFOS //////////////////////////////////////////////////////////
321321
/////////////////////////////////////////////////////////////////////////////////////
322322

323-
IGFD::FileStyle::FileStyle() : color(0, 0, 0, 0)
323+
IGFD::FileStyle::FileStyle()
324+
: color(0, 0, 0, 0)
324325
{
325326

326327
}
@@ -333,11 +334,10 @@ namespace IGFD
333334
flags = vStyle.flags;
334335
}
335336

336-
IGFD::FileStyle::FileStyle(const ImVec4& vColor, const std::string& vIcon, ImFont* vFont)
337+
IGFD::FileStyle::FileStyle(const ImVec4& vColor, const std::string& vIcon, ImFont* vFont)
338+
: color(vColor), icon(vIcon), font(vFont)
337339
{
338-
color = vColor;
339-
icon = vIcon;
340-
font = vFont;
340+
341341
}
342342

343343
/////////////////////////////////////////////////////////////////////////////////////
@@ -605,7 +605,7 @@ namespace IGFD
605605

606606
if (!res.isOk)
607607
{
608-
res.name = pfn;
608+
res.name = std::move(pfn);
609609
res.isOk = true;
610610
}
611611
}
@@ -785,7 +785,7 @@ namespace IGFD
785785
if (!token.empty())
786786
{
787787
FilterInfosStruct infos;
788-
infos.filter = token;
788+
infos.filter = std::move(token);
789789
prParsedFilters.emplace_back(infos);
790790
}
791791

@@ -1141,7 +1141,7 @@ namespace IGFD
11411141
return prSelectedFilter;
11421142
}
11431143

1144-
std::string IGFD::FilterManager::ReplaceExtentionWithCurrentFilter(const std::string vFile) const
1144+
std::string IGFD::FilterManager::ReplaceExtentionWithCurrentFilter(const std::string& vFile) const
11451145
{
11461146
auto result = vFile;
11471147

@@ -1455,9 +1455,9 @@ namespace IGFD
14551455
infos->fileNameExt_optimized = prOptimizeFilenameForSearchOperations(infos->fileNameExt);
14561456
infos->fileType = vFileType;
14571457

1458-
if (infos->fileNameExt.empty() || (infos->fileNameExt == "." && !vFileDialogInternal.puFilterManager.puDLGFilters.empty())) return; // filename empty or filename is the current dir '.'
1458+
if (infos->fileNameExt.empty() || (infos->fileNameExt == "." && !vFileDialogInternal.puFilterManager.puDLGFilters.empty())) return; // filename empty or filename is the current dir '.' //-V807
14591459
if (infos->fileNameExt != ".." && (vFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_DontShowHiddenFiles) && infos->fileNameExt[0] == '.') // dont show hidden files
1460-
if (!vFileDialogInternal.puFilterManager.puDLGFilters.empty() || (vFileDialogInternal.puFilterManager.puDLGFilters.empty() && infos->fileNameExt != ".")) // except "." if in directory mode
1460+
if (!vFileDialogInternal.puFilterManager.puDLGFilters.empty() || (vFileDialogInternal.puFilterManager.puDLGFilters.empty() && infos->fileNameExt != ".")) // except "." if in directory mode //-V728
14611461
return;
14621462

14631463
if (infos->fileType == 'f' ||
@@ -1518,10 +1518,12 @@ namespace IGFD
15181518
}
15191519
#else // dirent
15201520
struct dirent** files = nullptr;
1521-
int n = scandir(path.c_str(), &files, nullptr, inAlphaSort);
1522-
if (n > 0)
1521+
size_t n = scandir(path.c_str(), &files, nullptr, inAlphaSort);
1522+
if (n)
15231523
{
1524-
for (int i = 0; i < n; i++)
1524+
size_t i;
1525+
1526+
for (i = 0; i < n; i++)
15251527
{
15261528
struct dirent* ent = files[i];
15271529

@@ -1541,7 +1543,7 @@ namespace IGFD
15411543
AddFile(vFileDialogInternal, path, fileNameExt, fileType);
15421544
}
15431545

1544-
for (int i = 0; i < n; i++)
1546+
for (i = 0; i < n; i++)
15451547
{
15461548
free(files[i]);
15471549
}
@@ -1566,8 +1568,7 @@ namespace IGFD
15661568
{
15671569
auto info = std::make_shared<FileInfos>();
15681570
info->fileNameExt = drive;
1569-
info->fileNameExt_optimized = drive;
1570-
prOptimizeFilenameForSearchOperations(info->fileNameExt_optimized);
1571+
info->fileNameExt_optimized = prOptimizeFilenameForSearchOperations(drive);
15711572
info->fileType = 'd';
15721573

15731574
if (!info->fileNameExt.empty())
@@ -1825,7 +1826,7 @@ namespace IGFD
18251826
if (numchar != nullptr)
18261827
#endif // WIN32
18271828
{
1828-
prCurrentPath = real_path;
1829+
prCurrentPath = std::move(real_path);
18291830
if (prCurrentPath[prCurrentPath.size() - 1] == PATH_SEP)
18301831
{
18311832
prCurrentPath = prCurrentPath.substr(0, prCurrentPath.size() - 1);
@@ -1894,7 +1895,7 @@ namespace IGFD
18941895
--vIter;
18951896
}
18961897

1897-
prCurrentPath = res;
1898+
prCurrentPath = std::move(res);
18981899
}
18991900

19001901
bool IGFD::FileManager::SetPathOnParentDirectoryIfAny()
@@ -2433,14 +2434,13 @@ namespace IGFD
24332434
std::shared_ptr<FileInfos> file = nullptr;
24342435
prThumbnailFileDatasToGetMutex.lock();
24352436
//get the first file in the list
2436-
if (!prThumbnailFileDatasToGet.empty())
2437-
file = (*prThumbnailFileDatasToGet.begin());
2437+
file = (*prThumbnailFileDatasToGet.begin());
24382438
prThumbnailFileDatasToGetMutex.unlock();
24392439

24402440
// retrieve datas of the texture file if its an image file
24412441
if (file.use_count())
24422442
{
2443-
if (file->fileType == 'f')
2443+
if (file->fileType == 'f') //-V522
24442444
{
24452445
if (file->fileExt == ".png"
24462446
|| file->fileExt == ".bmp"
@@ -2464,39 +2464,41 @@ namespace IGFD
24642464
if (w && h)
24652465
{
24662466
// resize with respect to glyph ratio
2467-
float ratioX = (float)w / (float)h;
2468-
float newX = DisplayMode_ThumbailsList_ImageHeight * ratioX;
2467+
const float ratioX = (float)w / (float)h;
2468+
const float newX = DisplayMode_ThumbailsList_ImageHeight * ratioX;
24692469
float newY = w / ratioX;
24702470
if (newX < w)
24712471
newY = DisplayMode_ThumbailsList_ImageHeight;
24722472

24732473
const auto newWidth = (int)newX;
24742474
const auto newHeight = (int)newY;
2475-
const auto newBufSize = (size_t)(newWidth * newHeight * 4);
2475+
const auto newBufSize = (size_t)(newWidth * newHeight * 4U); //-V112 //-V1028
24762476
auto resizedData = new uint8_t[newBufSize];
24772477

24782478
const int resizeSucceeded = stbir_resize_uint8(
24792479
datas, w, h, 0,
24802480
resizedData, newWidth, newHeight, 0,
2481-
4);
2481+
4); //-V112
24822482

24832483
if (resizeSucceeded)
24842484
{
2485-
file->thumbnailInfo.textureFileDatas = resizedData;
2486-
file->thumbnailInfo.textureWidth = newWidth;
2487-
file->thumbnailInfo.textureHeight = newHeight;
2488-
file->thumbnailInfo.textureChannels = 4;
2485+
auto th = &file->thumbnailInfo;
2486+
2487+
th->textureFileDatas = resizedData;
2488+
th->textureWidth = newWidth;
2489+
th->textureHeight = newHeight;
2490+
th->textureChannels = 4; //-V112
24892491

24902492
// we set that at least, because will launch the gpu creation of the texture in the main thread
2491-
file->thumbnailInfo.isReadyToUpload = true;
2493+
th->isReadyToUpload = true;
24922494

24932495
// need gpu loading
24942496
prAddThumbnailToCreate(file);
24952497
}
24962498
}
24972499
else
24982500
{
2499-
printf("image loading fail : w:%i h:%i c:%i\n", w, h, 4);
2501+
printf("image loading fail : w:%i h:%i c:%i\n", w, h, 4); //-V112
25002502
}
25012503

25022504
stbi_image_free(datas);
@@ -2513,8 +2515,6 @@ namespace IGFD
25132515
}
25142516
}
25152517
}
2516-
2517-
prIsWorking = false;
25182518
}
25192519

25202520
inline void inVariadicProgressBar(float fraction, const ImVec2& size_arg, const char* fmt, ...)
@@ -2581,7 +2581,7 @@ namespace IGFD
25812581
}
25822582
}
25832583

2584-
void IGFD::ThumbnailFeature::prAddThumbnailToDestroy(IGFD_Thumbnail_Info vIGFD_Thumbnail_Info)
2584+
void IGFD::ThumbnailFeature::prAddThumbnailToDestroy(const IGFD_Thumbnail_Info& vIGFD_Thumbnail_Info)
25852585
{
25862586
// write => thread concurency issues
25872587
prThumbnailToDestroyMutex.lock();
@@ -2622,7 +2622,7 @@ namespace IGFD
26222622
auto file = vFileDialogInternal.puFileManager.GetFullFileAt(idx);
26232623
if (file.use_count())
26242624
{
2625-
if (file->thumbnailInfo.isReadyToDisplay)
2625+
if (file->thumbnailInfo.isReadyToDisplay) //-V522
26262626
{
26272627
prAddThumbnailToDestroy(file->thumbnailInfo);
26282628
}
@@ -2741,7 +2741,7 @@ namespace IGFD
27412741
ImGui::PushItemWidth(vSize.x - ImGui::GetCursorPosX());
27422742
if (ImGui::InputText("##ImGuiFileDialogBookmarkEdit", prBookmarkEditBuffer, MAX_FILE_DIALOG_NAME_BUFFER))
27432743
{
2744-
prBookmarks[selectedBookmarkForEdition].name = std::string(prBookmarkEditBuffer);
2744+
prBookmarks[(size_t)selectedBookmarkForEdition].name = std::string(prBookmarkEditBuffer);
27452745
}
27462746
ImGui::PopItemWidth();
27472747
}
@@ -2757,7 +2757,7 @@ namespace IGFD
27572757
for (int i = prBookmarkClipper.DisplayStart; i < prBookmarkClipper.DisplayEnd; i++)
27582758
{
27592759
if (i < 0) continue;
2760-
const BookmarkStruct& bookmark = prBookmarks[i];
2760+
const BookmarkStruct& bookmark = prBookmarks[(size_t)i];
27612761
ImGui::PushID(i);
27622762
if (ImGui::Selectable(bookmark.name.c_str(), selectedBookmarkForEdition == i,
27632763
ImGuiSelectableFlags_AllowDoubleClick) |
@@ -2777,7 +2777,7 @@ namespace IGFD
27772777
}
27782778
ImGui::PopID();
27792779
if (ImGui::IsItemHovered())
2780-
ImGui::SetTooltip("%s", bookmark.path.c_str());
2780+
ImGui::SetTooltip("%s", bookmark.path.c_str()); //-V111
27812781
}
27822782
}
27832783
prBookmarkClipper.End();
@@ -2844,7 +2844,7 @@ namespace IGFD
28442844
auto nfo = fdi.GetFilteredFileAt(i);
28452845
if (nfo.use_count())
28462846
{
2847-
if (nfo->fileNameExt_optimized[0] == vC || // lower case search
2847+
if (nfo->fileNameExt_optimized[0] == vC || // lower case search //-V522
28482848
nfo->fileNameExt[0] == vC) // maybe upper case search
28492849
{
28502850
//float p = ((float)i) * ImGui::GetTextLineHeightWithSpacing();
@@ -2857,7 +2857,7 @@ namespace IGFD
28572857
auto infos = fdi.GetFilteredFileAt(prLocateFileByInputChar_lastFileIdx);
28582858
if (infos.use_count())
28592859
{
2860-
if (infos->fileType == 'd')
2860+
if (infos->fileType == 'd') //-V522
28612861
{
28622862
if (fdi.puDLGDirectoryMode) // directory chooser
28632863
{
@@ -2997,7 +2997,7 @@ namespace IGFD
29972997
auto infos = fdi.GetFilteredFileAt(prLocateFileByInputChar_lastFileIdx);
29982998
if (infos.use_count())
29992999
{
3000-
if (infos->fileType == 'd')
3000+
if (infos->fileType == 'd') //-V522
30013001
{
30023002
if (!fdi.puDLGDirectoryMode || enterInDirectory)
30033003
{
@@ -3072,7 +3072,7 @@ namespace IGFD
30723072
// Submit label or explicit size to ItemSize(), whereas ItemAdd() will submit a larger/spanning rectangle.
30733073
ImGuiID id = window->GetID(label);
30743074
ImVec2 label_size = CalcTextSize(label, nullptr, true);
3075-
ImVec2 size(size_arg.x != 0.0f ? size_arg.x : label_size.x, size_arg.y != 0.0f ? size_arg.y : label_size.y);
3075+
ImVec2 size(size_arg.x != 0.0f ? size_arg.x : label_size.x, size_arg.y != 0.0f ? size_arg.y : label_size.y); //-V550
30763076
ImVec2 pos = window->DC.CursorPos;
30773077
pos.y += window->DC.CurrLineTextBaseOffset;
30783078
ItemSize(size, 0.0f);
@@ -3082,7 +3082,7 @@ namespace IGFD
30823082
const bool span_all_columns = (flags & ImGuiSelectableFlags_SpanAllColumns) != 0;
30833083
const float min_x = span_all_columns ? window->ParentWorkRect.Min.x : pos.x;
30843084
const float max_x = span_all_columns ? window->ParentWorkRect.Max.x : window->WorkRect.Max.x;
3085-
if (size_arg.x == 0.0f || (flags & ImGuiSelectableFlags_SpanAvailWidth))
3085+
if (fabs(size_arg.x) < FLT_EPSILON || (flags & ImGuiSelectableFlags_SpanAvailWidth))
30863086
size.x = ImMax(label_size.x, max_x - min_x);
30873087

30883088
// Text stays at the submission position, but bounding box may be extended on both sides
@@ -3297,7 +3297,7 @@ namespace IGFD
32973297
else
32983298
prFileDialogInternal.puFileManager.puDLGpath = vPath;
32993299
prFileDialogInternal.puFileManager.SetCurrentPath(vPath);
3300-
prFileDialogInternal.puFileManager.puDLGcountSelectionMax = vCountSelectionMax;
3300+
prFileDialogInternal.puFileManager.puDLGcountSelectionMax = (size_t)vCountSelectionMax;
33013301
prFileDialogInternal.puFileManager.SetDefaultFileName(vFileName);
33023302

33033303
prFileDialogInternal.puFileManager.ClearAll();
@@ -3386,7 +3386,7 @@ namespace IGFD
33863386
prFileDialogInternal.puFilterManager.puDLGdefaultExt.clear();
33873387
prFileDialogInternal.puFilterManager.ParseFilters(vFilters);
33883388

3389-
prFileDialogInternal.puFileManager.puDLGcountSelectionMax = vCountSelectionMax;
3389+
prFileDialogInternal.puFileManager.puDLGcountSelectionMax = (size_t)vCountSelectionMax;
33903390
prFileDialogInternal.puFileManager.puDLGDirectoryMode = (vFilters == nullptr);
33913391
if (vPath.empty())
33923392
prFileDialogInternal.puFileManager.puDLGpath = prFileDialogInternal.puFileManager.GetCurrentPath();
@@ -3856,7 +3856,7 @@ namespace IGFD
38563856
h = DisplayMode_ThumbailsList_ImageHeight;
38573857
#endif // USE_THUMBNAILS
38583858
#ifdef USE_EXPLORATION_BY_KEYS
3859-
bool flashed = prBeginFlashItem(vidx);
3859+
bool flashed = prBeginFlashItem((size_t)vidx);
38603860
bool res = prFlashableSelectable(fdi.puVariadicBuffer, vSelected, selectableFlags,
38613861
flashed, ImVec2(-1.0f, h));
38623862
if (flashed)
@@ -3910,7 +3910,7 @@ namespace IGFD
39103910
vOutStr.clear();
39113911
vOutShowColor = false;
39123912

3913-
if (vFileInfos->fileStyle.use_count())
3913+
if (vFileInfos->fileStyle.use_count()) //-V807 //-V522
39143914
{
39153915
vOutShowColor = true;
39163916

@@ -3930,7 +3930,7 @@ namespace IGFD
39303930
ImGui::PushFont(*vOutFont);
39313931
}
39323932

3933-
void IGFD::FileDialog::prEndFileColorIconStyle(bool& vShowColor, ImFont* vFont)
3933+
void IGFD::FileDialog::prEndFileColorIconStyle(const bool& vShowColor, ImFont* vFont)
39343934
{
39353935
if (vFont)
39363936
ImGui::PopFont();
@@ -3952,7 +3952,7 @@ namespace IGFD
39523952
#endif // USE_CUSTOM_SORTING_ICON
39533953
;
39543954
auto listViewID = ImGui::GetID("##FileDialog_fileTable");
3955-
if (ImGui::BeginTableEx("##FileDialog_fileTable", listViewID, 4, flags, vSize, 0.0f))
3955+
if (ImGui::BeginTableEx("##FileDialog_fileTable", listViewID, 4, flags, vSize, 0.0f)) //-V112
39563956
{
39573957
ImGui::TableSetupScrollFreeze(0, 1); // Make header always visible
39583958
ImGui::TableSetupColumn(fdi.puHeaderFileName.c_str(), ImGuiTableColumnFlags_WidthStretch, -1, 0);
@@ -3985,7 +3985,7 @@ namespace IGFD
39853985
ImGui::TableHeadersRow();
39863986
#else // USE_CUSTOM_SORTING_ICON
39873987
ImGui::TableNextRow(ImGuiTableRowFlags_Headers);
3988-
for (int column = 0; column < 4; column++)
3988+
for (int column = 0; column < 4; column++) //-V112
39893989
{
39903990
ImGui::TableSetColumnIndex(column);
39913991
const char* column_name = ImGui::TableGetColumnName(column); // Retrieve name passed to TableSetupColumn()
@@ -4109,7 +4109,7 @@ namespace IGFD
41094109
ImGui::TableSetupColumn(fdi.puHeaderFileDate.c_str(), ImGuiTableColumnFlags_WidthFixed |
41104110
((prFileDialogInternal.puDLGflags & ImGuiFileDialogFlags_HideColumnDate) ? ImGuiTableColumnFlags_DefaultHide : 0), -1, 3);
41114111
// not needed to have an option for hide the thumbnails since this is why this view is used
4112-
ImGui::TableSetupColumn(fdi.puHeaderFileThumbnails.c_str(), ImGuiTableColumnFlags_WidthFixed, -1, 4);
4112+
ImGui::TableSetupColumn(fdi.puHeaderFileThumbnails.c_str(), ImGuiTableColumnFlags_WidthFixed, -1, 4); //-V112
41134113

41144114
#ifndef USE_CUSTOM_SORTING_ICON
41154115
// Sort our data if sort specs have been changed!
@@ -4209,16 +4209,18 @@ namespace IGFD
42094209
}
42104210
if (ImGui::TableNextColumn()) // file thumbnails
42114211
{
4212-
if (!infos->thumbnailInfo.isLoadingOrLoaded)
4212+
auto th = &infos->thumbnailInfo;
4213+
4214+
if (!th->isLoadingOrLoaded)
42134215
{
42144216
prAddThumbnailToLoad(infos);
42154217
}
4216-
if (infos->thumbnailInfo.isReadyToDisplay &&
4217-
infos->thumbnailInfo.textureID)
4218+
if (th->isReadyToDisplay &&
4219+
th->textureID)
42184220
{
4219-
ImGui::Image((ImTextureID)infos->thumbnailInfo.textureID,
4220-
ImVec2((float)infos->thumbnailInfo.textureWidth,
4221-
(float)infos->thumbnailInfo.textureHeight));
4221+
ImGui::Image((ImTextureID)th->textureID,
4222+
ImVec2((float)th->textureWidth,
4223+
(float)th->textureHeight));
42224224
}
42234225
}
42244226

@@ -4691,7 +4693,7 @@ IMGUIFILEDIALOG_API void IGFD_OpenPaneModal2(
46914693
{
46924694
if (vContext)
46934695
{
4694-
vContext->OpenDialog(
4696+
vContext->OpenModal(
46954697
vKey, vTitle, vFilters,
46964698
vFilePathName,
46974699
vSidePane, vSidePaneWidth,
@@ -4924,7 +4926,7 @@ IMGUIFILEDIALOG_API void* IGFD_GetUserDatas(ImGuiFileDialog* vContext)
49244926
}
49254927

49264928
IMGUIFILEDIALOG_API void IGFD_SetFileStyle(ImGuiFileDialog* vContext,
4927-
IGFD_FileStyleFlags vFlags, const char* vCriteria, ImVec4 vColor, const char* vIcon, ImFont* vFont)
4929+
IGFD_FileStyleFlags vFlags, const char* vCriteria, ImVec4 vColor, const char* vIcon, ImFont* vFont) //-V813
49284930
{
49294931
if (vContext)
49304932
{

0 commit comments

Comments
 (0)