From 8a17c52c3bb5ef985e99bf90fb915ab3a285a543 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 2 Jul 2022 21:57:29 +0200 Subject: [PATCH] Fix wrong conversion of negative 64-bit wxAny to wxVariant Extracting the lower part of a 64-bit value only works when long is 32-bit, but not if it's 64-bit as well as is the case under LP64 Unix systems. Just use a normal cast to long instead, as this is simpler and works in all cases. Also add a simple unit test for this case, which would have previously failed, but passes now. Closes #22592. Closes #22595. --- src/common/any.cpp | 2 +- tests/any/anytest.cpp | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/common/any.cpp b/src/common/any.cpp index f47792366c..54640f8521 100644 --- a/src/common/any.cpp +++ b/src/common/any.cpp @@ -165,7 +165,7 @@ bool wxConvertAnyToVariant(const wxAny& any, wxVariant* variant) if ( ll > wxINT32_MAX || ll < wxINT32_MIN ) *variant = wxLongLong(ll); else - *variant = (long) wxLongLong(ll).GetLo(); + *variant = static_cast(ll); } else { diff --git a/tests/any/anytest.cpp b/tests/any/anytest.cpp index 08546a2949..b5375a1fb7 100644 --- a/tests/any/anytest.cpp +++ b/tests/any/anytest.cpp @@ -617,6 +617,12 @@ void wxAnyTestCase::wxVariantConversions() CPPUNIT_ASSERT(res); CPPUNIT_ASSERT(variant.GetType() == "ulonglong"); CPPUNIT_ASSERT(variant.GetULongLong() == wxULongLong(wxULL(123456))); + + any = (wxLongLong_t)-1; + res = any.GetAs(&variant); + CPPUNIT_ASSERT(res); + CPPUNIT_ASSERT(variant.GetType() == "long"); + CPPUNIT_ASSERT(variant.GetLong() == -1); #endif // Cannot test equality for the rest, just test that they convert