From: Jeffrey Altman Date: Mon, 10 May 2010 13:07:50 +0000 (-0400) Subject: Windows: Prevent overflow during percent used calc in Explorer Shell Ext X-Git-Tag: openafs-devel-1_5_75~292 X-Git-Url: https://git.michaelhowe.org/gitweb/?a=commitdiff_plain;h=953a2049a9a451a1f4015a64f8c5153044beba13;p=packages%2Fo%2Fopenafs.git Windows: Prevent overflow during percent used calc in Explorer Shell Ext 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 Reviewed-by: Jeffrey Altman --- diff --git a/src/WINNT/client_exp/partition_info_dlg.cpp b/src/WINNT/client_exp/partition_info_dlg.cpp index 9d7d31996..2c6f0c2d6 100644 --- a/src/WINNT/client_exp/partition_info_dlg.cpp +++ b/src/WINNT/client_exp/partition_info_dlg.cpp @@ -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 diff --git a/src/WINNT/client_exp/volume_inf.h b/src/WINNT/client_exp/volume_inf.h index 301fe9717..ce2847c81 100644 --- a/src/WINNT/client_exp/volume_inf.h +++ b/src/WINNT/client_exp/volume_inf.h @@ -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; }; diff --git a/src/WINNT/client_exp/volume_info.h b/src/WINNT/client_exp/volume_info.h index 27f8258a1..f709f47e3 100644 --- a/src/WINNT/client_exp/volume_info.h +++ b/src/WINNT/client_exp/volume_info.h @@ -35,7 +35,7 @@ public: CButton m_Ok; CButton m_ShowPartInfo; CListBox m_List; - long m_nNewQuota; + unsigned __int64 m_nNewQuota; //}}AFX_DATA diff --git a/src/WINNT/client_exp/volumeinfo.cpp b/src/WINNT/client_exp/volumeinfo.cpp index f077c4c82..83f6aa663 100644 --- a/src/WINNT/client_exp/volumeinfo.cpp +++ b/src/WINNT/client_exp/volumeinfo.cpp @@ -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,