Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/windirstat/windirstat.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFPtje <none@none>2015-11-05 21:49:14 +0300
committerFPtje <none@none>2015-11-05 21:49:14 +0300
commit160a305b3a32c943d5eb63a387221c678b2c6f8e (patch)
tree4d6d0fa53c1d102d920c7c199676223ca9fea1aa /windirstat
parent0fdc6a7e4b7d8463a72c9a021ebf8feb7e17a0b9 (diff)
Fixed WinDirStat's completely broken visualisation
The bug is caused by the fact that an unsigned long long minus an unsigned long long is ALWAYS positive. The quicksort function algorithm used `signum` to compare unsigned long longs. With signum always returning either 1 or 0 (because always positive), the sorting was pretty much useless. With an arbitrary sorting order in multiple locations of the program, nothing was grouped correctly and the wrong file extensions got a colour assigned. The bug was introduced in revision 151.
Diffstat (limited to 'windirstat')
-rw-r--r--windirstat/Controls/typeview.cpp4
-rw-r--r--windirstat/Dialogs/SelectDrivesDlg.cpp4
-rw-r--r--windirstat/dirstatdoc.cpp2
-rw-r--r--windirstat/item.cpp12
-rw-r--r--windirstat/stdafx.h3
5 files changed, 14 insertions, 11 deletions
diff --git a/windirstat/Controls/typeview.cpp b/windirstat/Controls/typeview.cpp
index 756bd7e..9b09372 100644
--- a/windirstat/Controls/typeview.cpp
+++ b/windirstat/Controls/typeview.cpp
@@ -182,13 +182,13 @@ int CExtensionListControl::CListItem::Compare(const CSortingListItem *baseOther,
case COL_COLOR:
case COL_BYTES:
{
- r = signum(m_record.bytes - other->m_record.bytes);
+ r = usignum(m_record.bytes, other->m_record.bytes);
}
break;
case COL_FILES:
{
- r = signum(m_record.files - other->m_record.files);
+ r = usignum(m_record.files, other->m_record.files);
}
break;
diff --git a/windirstat/Dialogs/SelectDrivesDlg.cpp b/windirstat/Dialogs/SelectDrivesDlg.cpp
index 7232211..7b23e21 100644
--- a/windirstat/Dialogs/SelectDrivesDlg.cpp
+++ b/windirstat/Dialogs/SelectDrivesDlg.cpp
@@ -166,12 +166,12 @@ int CDriveItem::Compare(const CSortingListItem *baseOther, int subitem) const
break;
case COL_TOTAL:
{
- r = signum(m_totalBytes - other->m_totalBytes);
+ r = usignum(m_totalBytes, other->m_totalBytes);
}
break;
case COL_FREE:
{
- r = signum(m_freeBytes - other->m_freeBytes);
+ r = usignum(m_freeBytes, other->m_freeBytes);
}
break;
case COL_GRAPH:
diff --git a/windirstat/dirstatdoc.cpp b/windirstat/dirstatdoc.cpp
index 01277ec..61e66c2 100644
--- a/windirstat/dirstatdoc.cpp
+++ b/windirstat/dirstatdoc.cpp
@@ -808,7 +808,7 @@ int __cdecl CDirstatDoc::_compareExtensions(const void *item1, const void *item2
SExtensionRecord r2;
VERIFY(_pqsortExtensionData->Lookup(*ext1, r1));
VERIFY(_pqsortExtensionData->Lookup(*ext2, r2));
- return signum(r2.bytes - r1.bytes);
+ return usignum(r2.bytes, r1.bytes);
}
void CDirstatDoc::SetWorkingItemAncestor(CItem *item)
diff --git a/windirstat/item.cpp b/windirstat/item.cpp
index 0219fe7..e4f188c 100644
--- a/windirstat/item.cpp
+++ b/windirstat/item.cpp
@@ -277,7 +277,7 @@ int CItem::CompareSibling(const CTreeListItem *tlib, int subitem) const
case COL_SUBTREEPERCENTAGE:
if(MustShowReadJobs())
{
- r = signum(m_readJobs - other->m_readJobs);
+ r = usignum(m_readJobs, other->m_readJobs);
}
else
{
@@ -293,25 +293,25 @@ int CItem::CompareSibling(const CTreeListItem *tlib, int subitem) const
case COL_SUBTREETOTAL:
{
- r = signum(GetSize() - other->GetSize());
+ r = usignum(GetSize(), other->GetSize());
}
break;
case COL_ITEMS:
{
- r = signum(GetItemsCount() - other->GetItemsCount());
+ r = usignum(GetItemsCount(), other->GetItemsCount());
}
break;
case COL_FILES:
{
- r = signum(GetFilesCount() - other->GetFilesCount());
+ r = usignum(GetFilesCount(), other->GetFilesCount());
}
break;
case COL_SUBDIRS:
{
- r = signum(GetSubdirsCount() - other->GetSubdirsCount());
+ r = usignum(GetSubdirsCount(), other->GetSubdirsCount());
}
break;
@@ -1650,7 +1650,7 @@ int __cdecl CItem::_compareBySize(const void *p1, const void *p2)
// TODO: Use 2nd sort column (as set in our TreeListView?)
- return signum(size2 - size1); // biggest first
+ return usignum(size2, size1); // biggest first
}
ULONGLONG CItem::GetProgressRangeMyComputer() const
diff --git a/windirstat/stdafx.h b/windirstat/stdafx.h
index 1514704..8c34010 100644
--- a/windirstat/stdafx.h
+++ b/windirstat/stdafx.h
@@ -78,6 +78,9 @@
template<class T> int signum(T x) { return (x) < 0 ? -1 : (x) == 0 ? 0 : 1; }
+/// signum function for unsigned numbers.
+template<class T> int usignum(T x, T y) { return (x) < (y) ? -1 : (x) == (y) ? 0 : 1; }
+
#define WEAK_ASSERT /##/ ASSERT
#endif // __WDS_STDAFX_H__