Windows: Prevent overflow during percent used calc in Explorer Shell Ext
authorJeffrey Altman <jaltman@your-file-system.com>
Mon, 10 May 2010 13:07:50 +0000 (09:07 -0400)
committerJeffrey Altman <jaltman@openafs.org>
Wed, 12 May 2010 05:27:53 +0000 (22:27 -0700)
In the Volume Info and Partition Info dialog boxes, percent used
was overflowing the variable due to using too small a variable
and multiplying before dividing.

FIXES 126846

Change-Id: I9a8a9275d22675cfb53c9e520758f2c4d6606954
Reviewed-on: http://gerrit.openafs.org/1939
Tested-by: Jeffrey Altman <jaltman@openafs.org>
Reviewed-by: Jeffrey Altman <jaltman@openafs.org>

src/WINNT/client_exp/partition_info_dlg.cpp
src/WINNT/client_exp/volume_inf.h
src/WINNT/client_exp/volume_info.h
src/WINNT/client_exp/volumeinfo.cpp

index 9d7d319..2c6f0c2 100644 (file)
@@ -75,11 +75,11 @@ BOOL CPartitionInfoDlg::OnInitDialog()
        strFree.Format(_T("%ld"), m_nFree);
        
        CString strPerUsed;
-       strPerUsed.Format(_T("%d"), ((m_nSize - m_nFree) * 100) / m_nSize);
+       strPerUsed.Format(_T("%d"), ((m_nSize - m_nFree) / m_nSize) * 100);
 
        m_Size.SetWindowText(strSize);
        m_Free.SetWindowText(strFree);
-    percentUsed = ( double(m_nSize - m_nFree) * 100.0l ) / double(m_nSize);
+    percentUsed = ( double(m_nSize - m_nFree) / double(m_nSize) * 100.0l);
     strPerUsed.Format(_T("%2.2lf"), percentUsed );
 
        return TRUE;  // return TRUE unless you set the focus to a control
index 301fe97..ce2847c 100644 (file)
@@ -16,12 +16,12 @@ public:
        CString m_strFilePath;
        CString m_strFileName;
        CString m_strName;
-       LONG m_nID;
-       LONG m_nQuota;
-       LONG m_nNewQuota;
-       LONG m_nUsed;
-       LONG m_nPartSize;
-       LONG m_nPartFree;
+       unsigned __int64 m_nID;
+       unsigned __int64 m_nQuota;
+       unsigned __int64 m_nNewQuota;
+       unsigned __int64 m_nUsed;
+       unsigned __int64 m_nPartSize;
+       unsigned __int64 m_nPartFree;
        int m_nDup;
        CString m_strErrorMsg;
 };
index 27f8258..f709f47 100644 (file)
@@ -35,7 +35,7 @@ public:
        CButton m_Ok;
        CButton m_ShowPartInfo;
        CListBox        m_List;
-       long    m_nNewQuota;
+       unsigned __int64 m_nNewQuota;
        //}}AFX_DATA
 
 
index f077c4c..83f6aa6 100644 (file)
@@ -201,7 +201,7 @@ void CVolumeInfo::OnDeltaPosQuotaSpin(NMHDR* pNMHDR, LRESULT* pResult)
 {
        NM_UPDOWN* pNMUpDown = (NM_UPDOWN*)pNMHDR;
        
-       LONG nNewQuota = m_nNewQuota + pNMUpDown->iDelta * 1024;
+       unsigned __int64 nNewQuota = m_nNewQuota + pNMUpDown->iDelta * 1024;
        if (nNewQuota < 0)
                return;
 
@@ -225,14 +225,14 @@ void CVolumeInfo::ShowInfo()
                        strEntry = m_pVolInfo[i].m_strFileName + "\t(Error:  " + m_pVolInfo[i].m_strErrorMsg + ")";
                else {
 
-                       LONG nQuota;
+                       unsigned __int64 nQuota;
                        if (m_pVolInfo[i].m_nDup == -1)
                                nQuota = m_pVolInfo[i].m_nNewQuota;
                        else
                                nQuota = m_pVolInfo[m_pVolInfo[i].m_nDup].m_nNewQuota;
 
                        if (nQuota != 0) {
-                               LONG nPercentUsed = (m_pVolInfo[i].m_nUsed * 100) / nQuota;
+                            LONG nPercentUsed = (LONG)((double)m_pVolInfo[i].m_nUsed / nQuota * 100);
                             strEntry.Format(_T("%s\t%s\t%ld\t%ldK\t%ldK\t%ld%%"),
                                             m_pVolInfo[i].m_strFileName,
                                             m_pVolInfo[i].m_strName,