lmi-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi-commits] [lmi] master 5cba997: Fix defect introduced 20111009T1501Z


From: Greg Chicares
Subject: [lmi-commits] [lmi] master 5cba997: Fix defect introduced 20111009T1501Z: wrong datatypes
Date: Tue, 5 Jun 2018 20:34:09 -0400 (EDT)

branch: master
commit 5cba997284029b086deb9f34b6a41abaf1eb541b
Author: Gregory W. Chicares <address@hidden>
Commit: Gregory W. Chicares <address@hidden>

    Fix defect introduced 20111009T1501Z: wrong datatypes
    
    wxDataViewListCtrl::GetItemCount() returns unsigned int, not long int.
    (It's notionally a signed int because it's not a bitfield and mod 2^N
    arithmetic is not wanted. It must be cast to long int because of the
    wxVariant API, but that's a separate issue.) wxSpinCtrl takes integer
    parameters, not long int. See:
      https://lists.nongnu.org/archive/html/lmi/2018-06/msg00004.html
    Replaced static_cast with bourn_cast, which does the same thing if the
    cast preserves value, but warns if it does not.
---
 census_view.cpp | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/census_view.cpp b/census_view.cpp
index e586aa3..600cc48 100644
--- a/census_view.cpp
+++ b/census_view.cpp
@@ -25,6 +25,7 @@
 
 #include "alert.hpp"
 #include "assert_lmi.hpp"
+#include "bourn_cast.hpp"
 #include "census_document.hpp"
 #include "configurable_settings.hpp"
 #include "contains.hpp"
@@ -233,9 +234,10 @@ wxWindow* IntSpinRenderer::DoCreateEditor
         ,rect.GetTopLeft()
         ,rect.GetSize()
         ,wxSP_ARROW_KEYS | wxTE_PROCESS_ENTER
-        ,static_cast<long int>(data.min)
-        ,static_cast<long int>(data.max)
-        ,value_cast <long int>(data.value));
+        ,bourn_cast<int>(data.min)
+        ,bourn_cast<int>(data.max)
+        ,value_cast<int>(data.value)
+        );
 }
 
 std::string IntSpinRenderer::DoGetValueFromEditor(wxWindow* editor)
@@ -761,7 +763,9 @@ void CensusViewDataViewModel::GetValueByRow(wxVariant& 
variant, unsigned int row
 {
     if(col == Col_CellNum)
         {
-        variant = static_cast<long int>(1 + row);
+        // WX !! wxVariant::operator=() is overloaded for numerous
+        // types, including 'long int' but excluding 'int'.
+        variant = static_cast<long int>(bourn_cast<int>(1 + row));
         }
     else
         {



reply via email to

[Prev in Thread] Current Thread [Next in Thread]